pub enum Value {
I32(i32),
I64(i64),
F32(f32),
F64(f64),
ExternRef(Option<ExternRef>),
FuncRef(Option<Function>),
V128(u128),
}
Expand description
WebAssembly computations manipulate values of basic value types:
- Integers (32 or 64 bit width)
- Floating-point (32 or 64 bit width)
- Vectors (128 bits, with 32 or 64 bit lanes)
Spec: https://webassembly.github.io/spec/core/exec/runtime.html#values
Variants§
I32(i32)
A 32-bit integer.
In Wasm integers are sign-agnostic, i.e. this can either be signed or unsigned.
I64(i64)
A 64-bit integer.
In Wasm integers are sign-agnostic, i.e. this can either be signed or unsigned.
F32(f32)
A 32-bit float.
F64(f64)
A 64-bit float.
ExternRef(Option<ExternRef>)
An externref
value which can hold opaque data to the wasm instance itself.
FuncRef(Option<Function>)
A first-class reference to a WebAssembly function.
V128(u128)
A 128-bit number
Implementations§
source§impl Value
impl Value
sourcepub fn as_raw(&self, store: &impl AsStoreRef) -> RawValue
pub fn as_raw(&self, store: &impl AsStoreRef) -> RawValue
Converts the Value
into a RawValue
.
sourcepub unsafe fn from_raw(
store: &mut impl AsStoreMut,
ty: Type,
raw: RawValue
) -> Self
pub unsafe fn from_raw( store: &mut impl AsStoreMut, ty: Type, raw: RawValue ) -> Self
Converts a RawValue
to a Value
.
Safety
sourcepub fn is_from_store(&self, store: &impl AsStoreRef) -> bool
pub fn is_from_store(&self, store: &impl AsStoreRef) -> bool
Checks whether a value can be used with the given context.
Primitive (i32
, i64
, etc) and null funcref/externref values are not
tied to a context and can be freely shared between contexts.
Externref and funcref values are tied to a context and can only be used with that context.
sourcepub fn i32(&self) -> Option<i32>
pub fn i32(&self) -> Option<i32>
Attempt to access the underlying value of this Value
, 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 Value
, 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 Value
, 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 Value
, 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 Value
, 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 Value
, 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 Value
, 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 Value
, 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 value of this Value
, returning
None
if it is not the correct type.
sourcepub fn unwrap_externref(&self) -> &Option<ExternRef>
pub fn unwrap_externref(&self) -> &Option<ExternRef>
Returns the underlying value of this Value
, panicking if it’s the
wrong type.
Panics
Panics if self
is not of the right type.
sourcepub fn funcref(&self) -> Option<&Option<Function>>
pub fn funcref(&self) -> Option<&Option<Function>>
Attempt to access the underlying value of this Value
, returning
None
if it is not the correct type.
sourcepub fn unwrap_funcref(&self) -> &Option<Function>
pub fn unwrap_funcref(&self) -> &Option<Function>
Returns the underlying value of this Value
, panicking if it’s the
wrong type.
Panics
Panics if self
is not of the right type.
sourcepub fn v128(&self) -> Option<u128>
pub fn v128(&self) -> Option<u128>
Attempt to access the underlying value of this Value
, returning
None
if it is not the correct type.
sourcepub fn unwrap_v128(&self) -> u128
pub fn unwrap_v128(&self) -> u128
Returns the underlying value of this Value
, panicking if it’s the
wrong type.
Panics
Panics if self
is not of the right type.