pub enum ValType {
I32,
I64,
F32,
F64,
V128,
Ref(RefType),
}
Expand description
A list of all possible value types in WebAssembly.
§Subtyping and Equality
ValType
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
ValType::matches
and Val::matches_ty
methods
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 ValType::eq
method.
Variants§
I32
Signed 32 bit integer.
I64
Signed 64 bit integer.
F32
Floating point 32 bit integer.
F64
Floating point 64 bit integer.
V128
A 128 bit number.
Ref(RefType)
An opaque reference to some type on the heap.
Implementations§
Source§impl ValType
impl ValType
Sourcepub const EXTERNREF: Self
Available on crate feature runtime
only.
pub const EXTERNREF: Self
runtime
only.The externref
type, aka (ref null extern)
.
Sourcepub const NULLEXTERNREF: Self
Available on crate feature runtime
only.
pub const NULLEXTERNREF: Self
runtime
only.The nullexternref
type, aka (ref null noextern)
.
Sourcepub const FUNCREF: Self
Available on crate feature runtime
only.
pub const FUNCREF: Self
runtime
only.The funcref
type, aka (ref null func)
.
Sourcepub const NULLFUNCREF: Self
Available on crate feature runtime
only.
pub const NULLFUNCREF: Self
runtime
only.The nullfuncref
type, aka (ref null nofunc)
.
Sourcepub const ANYREF: Self
Available on crate feature runtime
only.
pub const ANYREF: Self
runtime
only.The anyref
type, aka (ref null any)
.
Sourcepub const EQREF: Self
Available on crate feature runtime
only.
pub const EQREF: Self
runtime
only.The eqref
type, aka (ref null eq)
.
Sourcepub const I31REF: Self
Available on crate feature runtime
only.
pub const I31REF: Self
runtime
only.The i31ref
type, aka (ref null i31)
.
Sourcepub const ARRAYREF: Self
Available on crate feature runtime
only.
pub const ARRAYREF: Self
runtime
only.The arrayref
type, aka (ref null array)
.
Sourcepub const STRUCTREF: Self
Available on crate feature runtime
only.
pub const STRUCTREF: Self
runtime
only.The structref
type, aka (ref null struct)
.
Sourcepub const NULLREF: Self
Available on crate feature runtime
only.
pub const NULLREF: Self
runtime
only.The nullref
type, aka (ref null none)
.
Sourcepub const CONTREF: Self
Available on crate feature runtime
only.
pub const CONTREF: Self
runtime
only.The contref
type, aka (ref null cont)
.
Sourcepub const NULLCONTREF: Self
Available on crate feature runtime
only.
pub const NULLCONTREF: Self
runtime
only.The nullcontref
type, aka. (ref null nocont)
.
Sourcepub const EXNREF: Self
Available on crate feature runtime
only.
pub const EXNREF: Self
runtime
only.The exnref
type, aka (ref null exn)
.
Sourcepub const NULLEXNREF: Self
Available on crate feature runtime
only.
pub const NULLEXNREF: Self
runtime
only.The nullexnref
type, aka (ref null noexn)
.
Sourcepub fn is_num(&self) -> bool
Available on crate feature runtime
only.
pub fn is_num(&self) -> bool
runtime
only.Returns true if ValType
matches any of the numeric types. (e.g. I32
,
I64
, F32
, F64
).
Sourcepub fn is_ref(&self) -> bool
Available on crate feature runtime
only.
pub fn is_ref(&self) -> bool
runtime
only.Returns true if ValType
is any kind of reference type.
Sourcepub fn is_funcref(&self) -> bool
Available on crate feature runtime
only.
pub fn is_funcref(&self) -> bool
runtime
only.Is this the funcref
(aka (ref null func)
) type?
Sourcepub fn is_externref(&self) -> bool
Available on crate feature runtime
only.
pub fn is_externref(&self) -> bool
runtime
only.Is this the externref
(aka (ref null extern)
) type?
Sourcepub fn is_anyref(&self) -> bool
Available on crate feature runtime
only.
pub fn is_anyref(&self) -> bool
runtime
only.Is this the anyref
(aka (ref null any)
) type?
Sourcepub fn is_contref(&self) -> bool
Available on crate feature runtime
only.
pub fn is_contref(&self) -> bool
runtime
only.Is this the contref
(aka (ref null cont)
) type?
Sourcepub fn as_ref(&self) -> Option<&RefType>
Available on crate feature runtime
only.
pub fn as_ref(&self) -> Option<&RefType>
runtime
only.Get the underlying reference type, if this value type is a reference type.
Sourcepub fn unwrap_ref(&self) -> &RefType
Available on crate feature runtime
only.
pub fn unwrap_ref(&self) -> &RefType
runtime
only.Get the underlying reference type, panicking if this value type is not a reference type.
Sourcepub fn matches(&self, other: &ValType) -> bool
Available on crate feature runtime
only.
pub fn matches(&self, other: &ValType) -> bool
runtime
only.Does this value type match the other type?
That is, is this value type a subtype of the other?
§Panics
Panics if either type is associated with a different engine from the other.
Sourcepub fn eq(a: &Self, b: &Self) -> bool
Available on crate feature runtime
only.
pub fn eq(a: &Self, b: &Self) -> bool
runtime
only.Is value type a
precisely equal to value type b
?
Returns false
even if a
is a subtype of b
or vice versa, if they
are not exactly the same value type.
§Panics
Panics if either type is associated with a different engine.
Sourcepub fn default_value(&self) -> Option<Val>
Available on crate feature runtime
only.
pub fn default_value(&self) -> Option<Val>
runtime
only.Construct a default value. Returns None for non-nullable Ref types, which have no default.
Trait Implementations§
Source§impl From<ValType> for StorageType
Available on crate feature runtime
only.
impl From<ValType> for StorageType
runtime
only.Source§impl WasmType for ValType
Available on crate features wave
and runtime
only.
impl WasmType for ValType
wave
and runtime
only.Source§fn tuple_element_types(&self) -> Box<dyn Iterator<Item = Self> + '_>
fn tuple_element_types(&self) -> Box<dyn Iterator<Item = Self> + '_>
self
is not a tuple type. Read more§fn list_element_type(&self) -> Option<Self>
fn list_element_type(&self) -> Option<Self>
§fn record_fields(&self) -> Box<dyn Iterator<Item = (Cow<'_, str>, Self)> + '_>
fn record_fields(&self) -> Box<dyn Iterator<Item = (Cow<'_, str>, Self)> + '_>
self
is not a record type. Read more§fn variant_cases(
&self,
) -> Box<dyn Iterator<Item = (Cow<'_, str>, Option<Self>)> + '_>
fn variant_cases( &self, ) -> Box<dyn Iterator<Item = (Cow<'_, str>, Option<Self>)> + '_>
self
is not a tuple type. Read more§fn enum_cases(&self) -> Box<dyn Iterator<Item = Cow<'_, str>> + '_>
fn enum_cases(&self) -> Box<dyn Iterator<Item = Cow<'_, str>> + '_>
self
is not an enum type. Read more§fn option_some_type(&self) -> Option<Self>
fn option_some_type(&self) -> Option<Self>
§fn result_types(&self) -> Option<(Option<Self>, Option<Self>)>
fn result_types(&self) -> Option<(Option<Self>, Option<Self>)>
Auto Trait Implementations§
impl Freeze for ValType
impl !RefUnwindSafe for ValType
impl Send for ValType
impl Sync for ValType
impl Unpin for ValType
impl !UnwindSafe for ValType
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