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
sourceimpl 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.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Value
impl Send for Value
impl Sync for Value
impl Unpin for Value
impl UnwindSafe for Value
Blanket Implementations
impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
fn pointer_metadata(
&<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
fn pointer_metadata(
&<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<F, W, T, D> Deserialize<With<T, W>, D> for F where
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
impl<F, W, T, D> Deserialize<With<T, W>, D> for F where
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
Deserializes using the given deserializer
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T> Upcastable for T where
T: 'static + Any + Send + Sync,
impl<T> Upcastable for T where
T: 'static + Any + Send + Sync,
sourcefn upcast_any_ref(&self) -> &(dyn Any + 'static)
fn upcast_any_ref(&self) -> &(dyn Any + 'static)
upcast ref
sourcefn upcast_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn upcast_any_mut(&mut self) -> &mut (dyn Any + 'static)
upcast mut ref
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more