pub enum Val {
    I32(i32),
    I64(i64),
    F32(u32),
    F64(u64),
    V128(V128),
    FuncRef(Option<Func>),
    ExternRef(Option<Rooted<ExternRef>>),
    AnyRef(Option<Rooted<AnyRef>>),
    ExnRef(Option<Rooted<ExnRef>>),
    ContRef(Option<ContRef>),
}Expand description
Possible runtime values that a WebAssembly module can either consume or produce.
Note that we inline the enum Ref { ... } variants into enum Val { ... }
here as a size optimization.
Variants§
I32(i32)
A 32-bit integer.
I64(i64)
A 64-bit integer.
F32(u32)
A 32-bit float.
Note that the raw bits of the float are stored here, and you can use
f32::from_bits to create an f32 value.
F64(u64)
A 64-bit float.
Note that the raw bits of the float are stored here, and you can use
f64::from_bits to create an f64 value.
V128(V128)
A 128-bit number.
FuncRef(Option<Func>)
A function reference.
ExternRef(Option<Rooted<ExternRef>>)
An external reference.
AnyRef(Option<Rooted<AnyRef>>)
An internal reference.
ExnRef(Option<Rooted<ExnRef>>)
An exception reference.
ContRef(Option<ContRef>)
A continuation reference.
Note: This is currently a stub implementation as continuation objects are not yet fully integrated with the GC system. See #10248.
Implementations§
Source§impl Val
 
impl Val
Sourcepub fn null_ref(heap_type: &HeapType) -> Val
 
pub fn null_ref(heap_type: &HeapType) -> Val
Returns the null reference for the given heap type.
Sourcepub const fn null_func_ref() -> Val
 
pub const fn null_func_ref() -> Val
Returns the null function reference value.
The return value has type (ref null nofunc) aka nullfuncref and is a
subtype of all function references.
Sourcepub const fn null_extern_ref() -> Val
 
pub const fn null_extern_ref() -> Val
Returns the null function reference value.
The return value has type (ref null extern) aka nullexternref and is
a subtype of all external references.
Sourcepub const fn null_any_ref() -> Val
 
pub const fn null_any_ref() -> Val
Returns the null function reference value.
The return value has type (ref null any) aka nullref and is a
subtype of all internal references.
Sourcepub fn default_for_ty(ty: &ValType) -> Option<Val>
 
pub fn default_for_ty(ty: &ValType) -> Option<Val>
Returns the default value for the given type, if any exists.
Returns None if there is no default value for the given type (for
example, non-nullable reference types do not have a default value).
Sourcepub fn matches_ty(
    &self,
    store: impl AsContext,
    ty: &ValType,
) -> Result<bool, Error>
 
pub fn matches_ty( &self, store: impl AsContext, ty: &ValType, ) -> Result<bool, Error>
Does this value match the given type?
Returns an error is an underlying Rooted has been unrooted.
§Panics
Panics if this value is not associated with the given store.
Sourcepub fn to_raw(&self, store: impl AsContextMut) -> Result<ValRaw, Error>
 
pub fn to_raw(&self, store: impl AsContextMut) -> Result<ValRaw, Error>
Convenience method to convert this Val into a ValRaw.
Returns an error if this value is a GC reference and the GC reference has been unrooted.
§Safety
The returned ValRaw does not carry type information and is only safe
to use within the context of this store itself. For more information see
ExternRef::to_raw and Func::to_raw.
Sourcepub unsafe fn from_raw(
    store: impl AsContextMut,
    raw: ValRaw,
    ty: ValType,
) -> Val
 
pub unsafe fn from_raw( store: impl AsContextMut, raw: ValRaw, ty: ValType, ) -> Val
Convenience method to convert a ValRaw into a Val.
§Unsafety
This method is unsafe for the reasons that ExternRef::from_raw and
Func::from_raw are unsafe. Additionally there’s no guarantee
otherwise that raw should have the type ty specified.
Sourcepub fn i32(&self) -> Option<i32>
 
pub fn i32(&self) -> Option<i32>
Attempt to access the underlying value of this Val, returning
None if it is not the correct type.
Sourcepub fn unwrap_i32(&self) -> i32
 
pub fn unwrap_i32(&self) -> i32
Returns the underlying value of this Val, panicking if it’s the
wrong type.
§Panics
Panics if self is not of the right type.
Sourcepub fn i64(&self) -> Option<i64>
 
pub fn i64(&self) -> Option<i64>
Attempt to access the underlying value of this Val, returning
None if it is not the correct type.
Sourcepub fn unwrap_i64(&self) -> i64
 
pub fn unwrap_i64(&self) -> i64
Returns the underlying value of this Val, panicking if it’s the
wrong type.
§Panics
Panics if self is not of the right type.
Sourcepub fn f32(&self) -> Option<f32>
 
pub fn f32(&self) -> Option<f32>
Attempt to access the underlying value of this Val, returning
None if it is not the correct type.
Sourcepub fn unwrap_f32(&self) -> f32
 
pub fn unwrap_f32(&self) -> f32
Returns the underlying value of this Val, panicking if it’s the
wrong type.
§Panics
Panics if self is not of the right type.
Sourcepub fn f64(&self) -> Option<f64>
 
pub fn f64(&self) -> Option<f64>
Attempt to access the underlying value of this Val, returning
None if it is not the correct type.
Sourcepub fn unwrap_f64(&self) -> f64
 
pub fn unwrap_f64(&self) -> f64
Returns the underlying value of this Val, panicking if it’s the
wrong type.
§Panics
Panics if self is not of the right type.
Sourcepub fn func_ref(&self) -> Option<Option<&Func>>
 
pub fn func_ref(&self) -> Option<Option<&Func>>
Attempt to access the underlying value of this Val, returning
None if it is not the correct type.
Sourcepub fn unwrap_func_ref(&self) -> Option<&Func>
 
pub fn unwrap_func_ref(&self) -> Option<&Func>
Returns the underlying value of this Val, panicking if it’s the
wrong type.
§Panics
Panics if self is not of the right type.
Sourcepub fn extern_ref(&self) -> Option<Option<&Rooted<ExternRef>>>
 
pub fn extern_ref(&self) -> Option<Option<&Rooted<ExternRef>>>
Attempt to access the underlying value of this Val, returning
None if it is not the correct type.
Sourcepub fn unwrap_extern_ref(&self) -> Option<&Rooted<ExternRef>>
 
pub fn unwrap_extern_ref(&self) -> Option<&Rooted<ExternRef>>
Returns the underlying value of this Val, panicking if it’s the
wrong type.
§Panics
Panics if self is not of the right type.
Sourcepub fn any_ref(&self) -> Option<Option<&Rooted<AnyRef>>>
 
pub fn any_ref(&self) -> Option<Option<&Rooted<AnyRef>>>
Attempt to access the underlying value of this Val, returning
None if it is not the correct type.
Sourcepub fn unwrap_any_ref(&self) -> Option<&Rooted<AnyRef>>
 
pub fn unwrap_any_ref(&self) -> Option<&Rooted<AnyRef>>
Returns the underlying value of this Val, panicking if it’s the
wrong type.
§Panics
Panics if self is not of the right type.
Sourcepub fn v128(&self) -> Option<V128>
 
pub fn v128(&self) -> Option<V128>
Attempt to access the underlying value of this Val, returning
None if it is not the correct type.
Sourcepub fn unwrap_v128(&self) -> V128
 
pub fn unwrap_v128(&self) -> V128
Returns the underlying value of this Val, panicking if it’s the
wrong type.
§Panics
Panics if self is not of the right type.
Sourcepub fn externref(&self) -> Option<Option<&Rooted<ExternRef>>>
 
pub fn externref(&self) -> Option<Option<&Rooted<ExternRef>>>
Attempt to access the underlying externref value of this Val.
If this is not an externref, then None is returned.
If this is a null externref, then Some(None) is returned.
If this is a non-null externref, then Some(Some(..)) is returned.
Sourcepub fn unwrap_externref(&self) -> Option<&Rooted<ExternRef>>
 
pub fn unwrap_externref(&self) -> Option<&Rooted<ExternRef>>
Returns the underlying externref value of this Val, panicking if it’s the
wrong type.
If this is a null externref, then None is returned.
If this is a non-null externref, then Some(..) is returned.
§Panics
Panics if self is not a (nullable) externref.
Sourcepub fn anyref(&self) -> Option<Option<&Rooted<AnyRef>>>
 
pub fn anyref(&self) -> Option<Option<&Rooted<AnyRef>>>
Attempt to access the underlying anyref value of this Val.
If this is not an anyref, then None is returned.
If this is a null anyref, then Some(None) is returned.
If this is a non-null anyref, then Some(Some(..)) is returned.
Sourcepub fn unwrap_anyref(&self) -> Option<&Rooted<AnyRef>>
 
pub fn unwrap_anyref(&self) -> Option<&Rooted<AnyRef>>
Returns the underlying anyref value of this Val, panicking if it’s the
wrong type.
If this is a null anyref, then None is returned.
If this is a non-null anyref, then Some(..) is returned.
§Panics
Panics if self is not a (nullable) anyref.
Sourcepub fn exnref(&self) -> Option<Option<&Rooted<ExnRef>>>
 
pub fn exnref(&self) -> Option<Option<&Rooted<ExnRef>>>
Attempt to access the underlying exnref value of this Val.
If this is not an exnref, then None is returned.
If this is a null exnref, then Some(None) is returned.
If this is a non-null exnref, then Some(Some(..)) is returned.
Sourcepub fn unwrap_exnref(&self) -> Option<&Rooted<ExnRef>>
 
pub fn unwrap_exnref(&self) -> Option<&Rooted<ExnRef>>
Returns the underlying exnref value of this Val, panicking if it’s the
wrong type.
If this is a null exnref, then None is returned.
If this is a non-null exnref, then Some(..) is returned.
§Panics
Panics if self is not a (nullable) exnref.
Sourcepub fn funcref(&self) -> Option<Option<&Func>>
 
pub fn funcref(&self) -> Option<Option<&Func>>
Attempt to access the underlying funcref value of this Val.
If this is not an funcref, then None is returned.
If this is a null funcref, then Some(None) is returned.
If this is a non-null funcref, then Some(Some(..)) is returned.
Sourcepub fn unwrap_funcref(&self) -> Option<&Func>
 
pub fn unwrap_funcref(&self) -> Option<&Func>
Returns the underlying funcref value of this Val, panicking if it’s the
wrong type.
If this is a null funcref, then None is returned.
If this is a non-null funcref, then Some(..) is returned.
§Panics
Panics if self is not a (nullable) funcref.
Trait Implementations§
Source§impl WasmValue for Val
 
impl WasmValue for Val
Source§fn kind(&self) -> WasmTypeKind
 
fn kind(&self) -> WasmTypeKind
Source§fn make_tuple(
    ty: &<Val as WasmValue>::Type,
    vals: impl IntoIterator<Item = Val>,
) -> Result<Val, WasmValueError>
 
fn make_tuple( ty: &<Val as WasmValue>::Type, vals: impl IntoIterator<Item = Val>, ) -> Result<Val, WasmValueError>
Source§fn unwrap_s32(&self) -> i32
 
fn unwrap_s32(&self) -> i32
Source§fn unwrap_s64(&self) -> i64
 
fn unwrap_s64(&self) -> i64
Source§fn unwrap_f32(&self) -> f32
 
fn unwrap_f32(&self) -> f32
Source§fn unwrap_f64(&self) -> f64
 
fn unwrap_f64(&self) -> f64
Source§fn unwrap_tuple(&self) -> Box<dyn Iterator<Item = Cow<'_, Val>> + '_>
 
fn unwrap_tuple(&self) -> Box<dyn Iterator<Item = Cow<'_, Val>> + '_>
§fn make_string(val: Cow<'_, str>) -> Self
 
fn make_string(val: Cow<'_, str>) -> Self
§fn make_list(
    ty: &Self::Type,
    vals: impl IntoIterator<Item = Self>,
) -> Result<Self, WasmValueError>
 
fn make_list( ty: &Self::Type, vals: impl IntoIterator<Item = Self>, ) -> Result<Self, WasmValueError>
§fn make_record<'a>(
    ty: &Self::Type,
    fields: impl IntoIterator<Item = (&'a str, Self)>,
) -> Result<Self, WasmValueError>
 
fn make_record<'a>( ty: &Self::Type, fields: impl IntoIterator<Item = (&'a str, Self)>, ) -> Result<Self, WasmValueError>
§fn make_variant(
    ty: &Self::Type,
    case: &str,
    val: Option<Self>,
) -> Result<Self, WasmValueError>
 
fn make_variant( ty: &Self::Type, case: &str, val: Option<Self>, ) -> Result<Self, WasmValueError>
§fn make_enum(ty: &Self::Type, case: &str) -> Result<Self, WasmValueError>
 
fn make_enum(ty: &Self::Type, case: &str) -> Result<Self, WasmValueError>
§fn make_option(
    ty: &Self::Type,
    val: Option<Self>,
) -> Result<Self, WasmValueError>
 
fn make_option( ty: &Self::Type, val: Option<Self>, ) -> Result<Self, WasmValueError>
§fn make_result(
    ty: &Self::Type,
    val: Result<Option<Self>, Option<Self>>,
) -> Result<Self, WasmValueError>
 
fn make_result( ty: &Self::Type, val: Result<Option<Self>, Option<Self>>, ) -> Result<Self, WasmValueError>
§fn make_flags<'a>(
    ty: &Self::Type,
    names: impl IntoIterator<Item = &'a str>,
) -> Result<Self, WasmValueError>
 
fn make_flags<'a>( ty: &Self::Type, names: impl IntoIterator<Item = &'a str>, ) -> Result<Self, WasmValueError>
§fn unwrap_bool(&self) -> bool
 
fn unwrap_bool(&self) -> bool
§fn unwrap_s8(&self) -> i8
 
fn unwrap_s8(&self) -> i8
§fn unwrap_s16(&self) -> i16
 
fn unwrap_s16(&self) -> i16
§fn unwrap_u8(&self) -> u8
 
fn unwrap_u8(&self) -> u8
§fn unwrap_u16(&self) -> u16
 
fn unwrap_u16(&self) -> u16
§fn unwrap_u32(&self) -> u32
 
fn unwrap_u32(&self) -> u32
§fn unwrap_u64(&self) -> u64
 
fn unwrap_u64(&self) -> u64
§fn unwrap_char(&self) -> char
 
fn unwrap_char(&self) -> char
§fn unwrap_string(&self) -> Cow<'_, str>
 
fn unwrap_string(&self) -> Cow<'_, str>
§fn unwrap_list(&self) -> Box<dyn Iterator<Item = Cow<'_, Self>> + '_>
 
fn unwrap_list(&self) -> Box<dyn Iterator<Item = Cow<'_, Self>> + '_>
§fn unwrap_record(
    &self,
) -> Box<dyn Iterator<Item = (Cow<'_, str>, Cow<'_, Self>)> + '_>
 
fn unwrap_record( &self, ) -> Box<dyn Iterator<Item = (Cow<'_, str>, Cow<'_, Self>)> + '_>
§fn unwrap_variant(&self) -> (Cow<'_, str>, Option<Cow<'_, Self>>)
 
fn unwrap_variant(&self) -> (Cow<'_, str>, Option<Cow<'_, Self>>)
§fn unwrap_enum(&self) -> Cow<'_, str>
 
fn unwrap_enum(&self) -> Cow<'_, str>
§fn unwrap_option(&self) -> Option<Cow<'_, Self>>
 
fn unwrap_option(&self) -> Option<Cow<'_, Self>>
impl Copy for Val
Auto Trait Implementations§
impl Freeze for Val
impl RefUnwindSafe for Val
impl Send for Val
impl Sync for Val
impl Unpin for Val
impl UnwindSafe for Val
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,
§impl<T> Instrument for T
 
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
 
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
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