pub struct StructType { /* private fields */ }
Expand description
The type of a WebAssembly struct.
WebAssembly structs are a static, fixed-length, ordered sequence of
fields. Fields are named by index, not an identifier. Each field is mutable
or constant and stores unpacked Val
s or packed 8-/16-bit
integers.
§Subtyping and Equality
StructType
does not implement Eq
, because reference types have a
subtyping relationship, and so 99.99% of the time you actually want to check
whether one type matches (i.e. is a subtype of) another type. You can use
the StructType::matches
method to perform these types of checks. If,
however, you are in that 0.01% scenario where you need to check precise
equality between types, you can use the StructType::eq
method.
Implementations§
Source§impl StructType
impl StructType
Sourcepub fn new(
engine: &Engine,
fields: impl IntoIterator<Item = FieldType>,
) -> Result<Self>
Available on crate feature runtime
only.
pub fn new( engine: &Engine, fields: impl IntoIterator<Item = FieldType>, ) -> Result<Self>
runtime
only.Construct a new StructType
with the given field types.
This StructType
will be final and without a supertype.
The result will be associated with the given engine, and attempts to use it with other engines will panic (for example, checking whether it is a subtype of another struct type that is associated with a different engine).
Returns an error if the number of fields exceeds the implementation limit.
§Panics
Panics if any given field type is not associated with the given engine.
Sourcepub fn with_finality_and_supertype(
engine: &Engine,
finality: Finality,
supertype: Option<&Self>,
fields: impl IntoIterator<Item = FieldType>,
) -> Result<Self>
Available on crate feature runtime
only.
pub fn with_finality_and_supertype( engine: &Engine, finality: Finality, supertype: Option<&Self>, fields: impl IntoIterator<Item = FieldType>, ) -> Result<Self>
runtime
only.Construct a new StructType
with the given finality, supertype, and
fields.
The result will be associated with the given engine, and attempts to use it with other engines will panic (for example, checking whether it is a subtype of another struct type that is associated with a different engine).
Returns an error if the number of fields exceeds the implementation limit, if the supertype is final, or if this type does not match the supertype.
§Panics
Panics if any given field type is not associated with the given engine.
Sourcepub fn engine(&self) -> &Engine
Available on crate feature runtime
only.
pub fn engine(&self) -> &Engine
runtime
only.Get the engine that this struct type is associated with.
Sourcepub fn finality(&self) -> Finality
Available on crate feature runtime
only.
pub fn finality(&self) -> Finality
runtime
only.Get the finality of this struct type.
Sourcepub fn supertype(&self) -> Option<Self>
Available on crate feature runtime
only.
pub fn supertype(&self) -> Option<Self>
runtime
only.Get the supertype of this struct type, if any.
Sourcepub fn field(&self, i: usize) -> Option<FieldType>
Available on crate feature runtime
only.
pub fn field(&self, i: usize) -> Option<FieldType>
runtime
only.Get the i
th field type.
Returns None
if i
is out of bounds.
Sourcepub fn fields(&self) -> impl ExactSizeIterator<Item = FieldType> + '_
Available on crate feature runtime
only.
pub fn fields(&self) -> impl ExactSizeIterator<Item = FieldType> + '_
runtime
only.Returns the list of field types for this function.
Sourcepub fn matches(&self, other: &StructType) -> bool
Available on crate feature runtime
only.
pub fn matches(&self, other: &StructType) -> bool
runtime
only.Does this struct type match the other struct type?
That is, is this function type a subtype of the other struct type?
§Panics
Panics if either type is associated with a different engine from the other.
Sourcepub fn eq(a: &StructType, b: &StructType) -> bool
Available on crate feature runtime
only.
pub fn eq(a: &StructType, b: &StructType) -> bool
runtime
only.Is struct type a
precisely equal to struct type b
?
Returns false
even if a
is a subtype of b
or vice versa, if they
are not exactly the same struct type.
§Panics
Panics if either type is associated with a different engine from the other.
Trait Implementations§
Source§impl Clone for StructType
Available on crate feature runtime
only.
impl Clone for StructType
runtime
only.Source§fn clone(&self) -> StructType
fn clone(&self) -> StructType
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for StructType
Available on crate feature runtime
only.
impl Debug for StructType
runtime
only.Source§impl Display for StructType
Available on crate feature runtime
only.
impl Display for StructType
runtime
only.Source§impl From<StructType> for HeapType
Available on crate feature runtime
only.
impl From<StructType> for HeapType
runtime
only.Source§fn from(s: StructType) -> Self
fn from(s: StructType) -> Self
Source§impl Hash for StructType
Available on crate feature runtime
only.
impl Hash for StructType
runtime
only.Auto Trait Implementations§
impl Freeze for StructType
impl !RefUnwindSafe for StructType
impl Send for StructType
impl Sync for StructType
impl Unpin for StructType
impl !UnwindSafe for StructType
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more