pub trait WasmType: Clone + Sized {
// Required method
fn kind(&self) -> WasmTypeKind;
// Provided methods
fn list_element_type(&self) -> Option<Self> { ... }
fn record_fields(
&self,
) -> Box<dyn Iterator<Item = (Cow<'_, str>, Self)> + '_> { ... }
fn tuple_element_types(&self) -> Box<dyn Iterator<Item = Self> + '_> { ... }
fn variant_cases(
&self,
) -> Box<dyn Iterator<Item = (Cow<'_, str>, Option<Self>)> + '_> { ... }
fn enum_cases(&self) -> Box<dyn Iterator<Item = Cow<'_, str>> + '_> { ... }
fn option_some_type(&self) -> Option<Self> { ... }
fn result_types(&self) -> Option<(Option<Self>, Option<Self>)> { ... }
fn flags_names(&self) -> Box<dyn Iterator<Item = Cow<'_, str>> + '_> { ... }
}
Expand description
The WasmType trait may be implemented to represent types to be
(de)serialized with WAVE, notably value::Type
.
The [wasmtime
] crate provides an impl for [wasmtime::component::Type
].
The Self
-returning methods should be called only for corresponding
WasmTypeKind
s.
Required Methods§
Sourcefn kind(&self) -> WasmTypeKind
fn kind(&self) -> WasmTypeKind
Returns the WasmTypeKind
of this type.
Provided Methods§
Sourcefn list_element_type(&self) -> Option<Self>
fn list_element_type(&self) -> Option<Self>
Returns the list element type or None
if self
is not a list type.
§Panics
Panics if the type is not implemented (the trait default).
Sourcefn record_fields(&self) -> Box<dyn Iterator<Item = (Cow<'_, str>, Self)> + '_>
fn record_fields(&self) -> Box<dyn Iterator<Item = (Cow<'_, str>, Self)> + '_>
Returns an iterator of the record’s field names and Types. The
iterator will be empty iff self
is not a record type.
§Panics
Panics if the type is not implemented (the trait default).
Sourcefn tuple_element_types(&self) -> Box<dyn Iterator<Item = Self> + '_>
fn tuple_element_types(&self) -> Box<dyn Iterator<Item = Self> + '_>
Returns an iterator of the tuple’s field Types. The iterator will be
empty iff self
is not a tuple type.
§Panics
Panics if the type is not implemented (the trait default).
Sourcefn variant_cases(
&self,
) -> Box<dyn Iterator<Item = (Cow<'_, str>, Option<Self>)> + '_>
fn variant_cases( &self, ) -> Box<dyn Iterator<Item = (Cow<'_, str>, Option<Self>)> + '_>
Returns an iterator of the variant’s case names and optional payload
Types. The iterator will be empty iff self
is not a tuple type.
§Panics
Panics if the type is not implemented (the trait default).
Sourcefn enum_cases(&self) -> Box<dyn Iterator<Item = Cow<'_, str>> + '_>
fn enum_cases(&self) -> Box<dyn Iterator<Item = Cow<'_, str>> + '_>
Returns an iterator of the enum’s case names. The iterator will be
empty iff self
is not an enum type.
§Panics
Panics if the type is not implemented (the trait default).
Sourcefn option_some_type(&self) -> Option<Self>
fn option_some_type(&self) -> Option<Self>
Returns the option’s “some” type or None
if self
is not an option type.
§Panics
Panics if the type is not implemented (the trait default).
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.