Enum wiggle::wasmtime_crate::Val
source · pub enum Val {
I32(i32),
I64(i64),
F32(u32),
F64(u64),
V128(V128),
FuncRef(Option<Func>),
ExternRef(Option<ExternRef>),
}
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<ExternRef>)
An external reference.
Implementations§
source§impl Val
impl Val
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 fn ty(&self, store: impl AsContext) -> ValType
pub fn ty(&self, store: impl AsContext) -> ValType
Returns the corresponding ValType
for this Val
.
sourcepub fn matches_ty(&self, store: impl AsContext, ty: &ValType) -> bool
pub fn matches_ty(&self, store: impl AsContext, ty: &ValType) -> bool
Does this value match the given type?
§Panics
Panics if this value is not associated with the given store.
sourcepub unsafe fn to_raw(&self, store: impl AsContextMut) -> ValRaw
pub unsafe fn to_raw(&self, store: impl AsContextMut) -> ValRaw
Convenience method to convert this Val
into a ValRaw
.
§Unsafety
This method is unsafe for the reasons that ExternRef::to_raw
and
Func::to_raw
are unsafe.
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. Additionaly 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<&ExternRef>>
pub fn extern_ref(&self) -> Option<Option<&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<&ExternRef>
pub fn unwrap_extern_ref(&self) -> Option<&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 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<&ExternRef>>
pub fn externref(&self) -> Option<Option<&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<&ExternRef>
pub fn unwrap_externref(&self) -> Option<&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 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
.