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<StructType, Error>
pub fn new( engine: &Engine, fields: impl IntoIterator<Item = FieldType>, ) -> Result<StructType, Error>
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<&StructType>,
fields: impl IntoIterator<Item = FieldType>,
) -> Result<StructType, Error>
pub fn with_finality_and_supertype( engine: &Engine, finality: Finality, supertype: Option<&StructType>, fields: impl IntoIterator<Item = FieldType>, ) -> Result<StructType, Error>
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 supertype(&self) -> Option<StructType>
pub fn supertype(&self) -> Option<StructType>
Get the supertype of this struct type, if any.
Sourcepub fn field(&self, i: usize) -> Option<FieldType>
pub fn field(&self, i: usize) -> Option<FieldType>
Get the i
th field type.
Returns None
if i
is out of bounds.
Sourcepub fn fields(&self) -> impl ExactSizeIterator
pub fn fields(&self) -> impl ExactSizeIterator
Returns the list of field types for this function.
Sourcepub fn matches(&self, other: &StructType) -> bool
pub fn matches(&self, other: &StructType) -> bool
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
pub fn eq(a: &StructType, b: &StructType) -> bool
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
impl Clone for StructType
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 more