Skip to main content

HostType

Enum HostType 

Source
pub enum HostType {
Show 13 variants Unit, Bool, Int, String, Duration, Error, Array(&'static HostType), Set(&'static HostType), Map(&'static HostType, &'static HostType), Option(&'static HostType), Result(&'static HostType, &'static HostType), Named(&'static str), Any,
}
Expand description

A type in a Host API signature, written in Cove’s source vocabulary.

This is a small enum rather than cove_syntax::ast::Type because an ast::Type is a parsed type: every node carries a span into a source file and its path segments are identifiers with spans of their own, all of which would have to be invented for an operation that has no source to point at. The rendering vocabulary is the same one — fmt::Display produces the form the type would be written in Cove — so a signature printed from a schema entry reads exactly like a signature written by hand.

Add a variant when a host needs it; an unused variant is a type nobody can produce. That used to read “the variants cover exactly the types the shipped hosts use”, and HostType::Set and HostType::Map are why it no longer does: no shipped host has needed either, and an embedder did (issue #153). An embedder is not a lesser kind of host — embedding is why HostApi is a trait — so the list is what a host may declare rather than what this workspace happens to ship, and crates/cove-runtime/tests/embedding.rs is where the two new ones are produced and consumed.

Variants§

§

Unit

Unit, the value an operation returns when it returns nothing.

§

Bool

Bool.

§

Int

Int, a signed 64-bit integer.

§

String

String.

§

Duration

Duration, a signed count of nanoseconds.

§

Error

Error, the builtin error struct.

§

Array(&'static HostType)

Array<T>, the fixed-length immutable sequence.

§

Set(&'static HostType)

Set<T>, the key-ordered immutable set.

T must be one HostType::may_be_a_key allows, because a Set element is a map key: ModuleSchema::validate is what refuses a declaration that says otherwise, and it refuses it where the schema is read rather than where a value is.

§

Map(&'static HostType, &'static HostType)

Map<K, V>, the key-ordered immutable map.

K carries the same restriction a HostType::Set element does, and for the same reason; V carries none.

§

Option(&'static HostType)

Option<T>.

§

Result(&'static HostType, &'static HostType)

Result<T, E>. Expected failure is part of an operation’s result type, exactly as it is in Cove source, rather than a second channel beside it.

§

Named(&'static str)

A type the host declares, written qualified: http.Response.

The name is the one Cove source writes, module included, because that is what a signature in a diagnostic has to read as. Whether it names a TypeSchema or a ResourceSchema is the host’s business; a signature says only which type it is.

§

Any

Any value at all.

This is not a missing type: it is the type of an operation whose meaning does not depend on which value it was given. http.json renders whatever it is handed, and a callback a host stores and calls later is a value the host never looks inside.

What it promises, and what it costs, are different at the two ends of a signature, and both are worth stating exactly.

In a parameter it promises that every value is accepted: no argument of any type is a mistake, the compiler rejects none, and the boundary rejects none either. Nothing is given up by it, because there was never a constraint to check.

In a result it says the operation may answer with a value of any type. That does cost something: from the call onwards the program holds a value no schema described, so the compiler cannot prove what a field read off it, a call made on it, or a place it is stored into will do. Those are checked at run time and by nothing before it. cove check reports each such call rather than letting the silence pass for a proof — as a note, because a schema declaring Any is a deliberate design decision and not a fault in the program that calls it.

Implementations§

Source§

impl HostType

Source

pub fn may_be_a_key(&self) -> bool

Whether a value of this type may be a Map key or a Set element.

Cove’s own rule is cove_runtime::value::MapKey’s: “mutable handles and structs containing them are not valid map keys”, because a key’s equality must not change while a collection holds it. That rule is about a value, and this is the most a name can say about it.

Everything made only of the scalar types qualifies, and so does any composition of qualifying types: an Array, an Option, a Result, a Set, or a Map is a key exactly when everything nested inside it is.

HostType::Named and HostType::Any do not, and the reason is the same in both cases: neither says what its values are made of. cove_runtime::schema::Admits checks a named type by the name the value carries and deliberately looks no further — ADR 0013’s amendment draws that line — so a schema naming reviews.PullRequest has made no claim about the ten fields behind it, and a ResourceSchema’s handle can never be a key at all. Any says less again. A declaration that promised more than the boundary checks would be a promise nothing keeps.

Trait Implementations§

Source§

impl Admits for HostType

Source§

fn admits(&self, value: &Value) -> Result<(), Mismatch>

Whether value is one this type admits, and where it stops being one when it is not. Read more
Source§

impl Clone for HostType

Source§

fn clone(&self) -> HostType

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for HostType

Source§

impl Debug for HostType

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Display for HostType

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Eq for HostType

Source§

impl PartialEq for HostType

Source§

fn eq(&self, other: &HostType) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for HostType

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.