pub(crate) struct TypeUniverse {
    pub namespace: NamespaceMetadata,
    pub namespace_docstring: Option<String>,
    type_definitions: HashMap<String, Type>,
    all_known_types: BTreeSet<Type>,
}
Expand description

The set of all possible types used in a particular component interface.

Every component API uses a finite number of types, including primitive types, API-defined types like records and enums, and recursive types such as sequences of the above. Our component API doesn’t support fancy generics so this is a finitely-enumerable set, which is useful to be able to operate on explicitly.

You could imagine this struct doing some clever interning of names and so-on in future, to reduce the overhead of passing around Type instances. For now we just do a whole lot of cloning.

Fields§

§namespace: NamespaceMetadata

The unique prefixes that we’ll use for namespacing when exposing this component’s API.

§namespace_docstring: Option<String>§type_definitions: HashMap<String, Type>§all_known_types: BTreeSet<Type>

Implementations§

source§

impl TypeUniverse

source

pub fn new(namespace: NamespaceMetadata) -> Self

source

fn add_type_definition(&mut self, name: &str, type_: &Type) -> Result<()>

Add the definition of a named Type.

source

pub(super) fn get_type_definition(&self, name: &str) -> Option<Type>

Get the Type corresponding to a given name, if any.

source

pub fn add_known_type(&mut self, type_: &Type) -> Result<()>

Add a Type to the set of all types seen in the component interface.

source

pub fn add_known_types(&mut self, types: TypeIterator<'_>) -> Result<()>

Add many Types…

source

pub fn iter_known_types(&self) -> impl Iterator<Item = &Type>

Iterator over all the known types in this universe.

Trait Implementations§

source§

impl Debug for TypeUniverse

source§

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

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

impl Default for TypeUniverse

source§

fn default() -> TypeUniverse

Returns the “default value” for a type. Read more

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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.