Enum wasmer::Value

source ·
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

source

pub fn null() -> Self

Returns a null externref value.

source

pub fn ty(&self) -> Type

Returns the corresponding Type for this Value.

source

pub fn as_raw(&self, store: &impl AsStoreRef) -> RawValue

Converts the Value into a RawValue.

source

pub unsafe fn from_raw( store: &mut impl AsStoreMut, ty: Type, raw: RawValue ) -> Self

Converts a RawValue to a Value.

Safety
source

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.

source

pub fn i32(&self) -> Option<i32>

Attempt to access the underlying value of this Value, returning None if it is not the correct type.

source

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.

source

pub fn i64(&self) -> Option<i64>

Attempt to access the underlying value of this Value, returning None if it is not the correct type.

source

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.

source

pub fn f32(&self) -> Option<f32>

Attempt to access the underlying value of this Value, returning None if it is not the correct type.

source

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.

source

pub fn f64(&self) -> Option<f64>

Attempt to access the underlying value of this Value, returning None if it is not the correct type.

source

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.

source

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.

source

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.

source

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.

source

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.

source

pub fn v128(&self) -> Option<u128>

Attempt to access the underlying value of this Value, returning None if it is not the correct type.

source

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§

source§

impl Clone for Value

source§

fn clone(&self) -> Value

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Value

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<ExternRef> for Value

source§

fn from(val: ExternRef) -> Self

Converts to this type from the input type.
source§

impl From<Function> for Value

source§

fn from(val: Function) -> Self

Converts to this type from the input type.
source§

impl From<Option<ExternRef>> for Value

source§

fn from(val: Option<ExternRef>) -> Self

Converts to this type from the input type.
source§

impl From<Option<Function>> for Value

source§

fn from(val: Option<Function>) -> Self

Converts to this type from the input type.
source§

impl From<f32> for Value

source§

fn from(val: f32) -> Self

Converts to this type from the input type.
source§

impl From<f64> for Value

source§

fn from(val: f64) -> Self

Converts to this type from the input type.
source§

impl From<i32> for Value

source§

fn from(val: i32) -> Self

Converts to this type from the input type.
source§

impl From<i64> for Value

source§

fn from(val: i64) -> Self

Converts to this type from the input type.
source§

impl From<u32> for Value

source§

fn from(val: u32) -> Self

Converts to this type from the input type.
source§

impl From<u64> for Value

source§

fn from(val: u64) -> Self

Converts to this type from the input type.
source§

impl PartialEq<Value> for Value

source§

fn eq(&self, o: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl ToString for Value

source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl TryFrom<Value> for Option<ExternRef>

§

type Error = &'static str

The type returned in the event of a conversion error.
source§

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Value> for Option<Function>

§

type Error = &'static str

The type returned in the event of a conversion error.
source§

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Value> for f32

§

type Error = &'static str

The type returned in the event of a conversion error.
source§

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Value> for f64

§

type Error = &'static str

The type returned in the event of a conversion error.
source§

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Value> for i32

§

type Error = &'static str

The type returned in the event of a conversion error.
source§

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Value> for i64

§

type Error = &'static str

The type returned in the event of a conversion error.
source§

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Value> for u32

§

type Error = &'static str

The type returned in the event of a conversion error.
source§

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Value> for u64

§

type Error = &'static str

The type returned in the event of a conversion error.
source§

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.

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§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> ArchivePointee for T

§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

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 Fwhere W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

§

fn deserialize( &self, deserializer: &mut D ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> LayoutRaw for T

§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Gets the layout of the type.
§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Pointee for T

§

type Metadata = ()

The type for metadata in pointers and references to Self.
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> Upcastable for Twhere T: Any + Send + Sync + 'static,

source§

fn upcast_any_ref(&self) -> &(dyn Any + 'static)

upcast ref
source§

fn upcast_any_mut(&mut self) -> &mut (dyn Any + 'static)

upcast mut ref
source§

fn upcast_any_box(self: Box<T, Global>) -> Box<dyn Any, Global>

upcast boxed dyn
source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more