pub enum Value<T> {
I32(i32),
I64(i64),
F32(f32),
F64(f64),
ExternRef(ExternRef),
FuncRef(Option<T>),
V128(u128),
}
Expand description
Possible runtime values that a WebAssembly module can either consume or produce.
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(ExternRef)
An externref
value which can hold opaque data to the wasm instance itself.
Note that this is a nullable value as well.
FuncRef(Option<T>)
A first-class reference to a WebAssembly function.
V128(u128)
A 128-bit number
Implementations§
Source§impl<T> Value<T>where
T: WasmValueType,
impl<T> Value<T>where
T: WasmValueType,
Sourcepub unsafe fn write_value_to(&self, p: *mut i128)
pub unsafe fn write_value_to(&self, p: *mut i128)
Writes it’s value to a given pointer
§Safety
p
must be:
- Sufficiently aligned for the Rust equivalent of the type in
self
- Non-null and pointing to valid, mutable memory
Sourcepub unsafe fn read_value_from(store: &dyn Any, p: *const i128, ty: Type) -> Self
pub unsafe fn read_value_from(store: &dyn Any, p: *const i128, ty: Type) -> Self
Gets a Value
given a pointer and a Type
§Safety
p
must be:
- Properly aligned to the specified
ty
’s Rust equivalent - Non-null and pointing to valid memory
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<ExternRef>
pub fn externref(&self) -> 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) -> ExternRef
pub fn unwrap_externref(&self) -> 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<T>>
pub fn funcref(&self) -> Option<&Option<T>>
Attempt to access the underlying value of this Value
, returning
None
if it is not the correct type.
Sourcepub fn unwrap_funcref(&self) -> &Option<T>
pub fn unwrap_funcref(&self) -> &Option<T>
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.