Struct wasmtime::StructType
source · 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>
pub fn new( engine: &Engine, fields: impl IntoIterator<Item = FieldType>, ) -> Result<Self>
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>
pub fn with_finality_and_supertype( engine: &Engine, finality: Finality, supertype: Option<&Self>, fields: impl IntoIterator<Item = FieldType>, ) -> Result<Self>
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 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<Item = FieldType> + '_
pub fn fields(&self) -> impl ExactSizeIterator<Item = FieldType> + '_
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 moresource§impl Debug for StructType
impl Debug for StructType
source§impl Display for StructType
impl Display for StructType
source§impl From<StructType> for HeapType
impl From<StructType> for HeapType
source§fn from(s: StructType) -> Self
fn from(s: StructType) -> Self
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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)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