Enum unc_vm_types::Value

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

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

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
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<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) -> 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<T>>

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<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.

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<T: Clone> Clone for Value<T>

source§

fn clone(&self) -> Value<T>

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<T> Debug for Value<T>
where T: WasmValueType,

source§

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

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

impl<T> From<ExternRef> for Value<T>
where T: WasmValueType,

source§

fn from(val: ExternRef) -> Self

Converts to this type from the input type.
source§

impl<T> From<f32> for Value<T>
where T: WasmValueType,

source§

fn from(val: f32) -> Self

Converts to this type from the input type.
source§

impl<T> From<f64> for Value<T>
where T: WasmValueType,

source§

fn from(val: f64) -> Self

Converts to this type from the input type.
source§

impl<T> From<i32> for Value<T>
where T: WasmValueType,

source§

fn from(val: i32) -> Self

Converts to this type from the input type.
source§

impl<T> From<i64> for Value<T>
where T: WasmValueType,

source§

fn from(val: i64) -> Self

Converts to this type from the input type.
source§

impl<T> From<u32> for Value<T>
where T: WasmValueType,

source§

fn from(val: u32) -> Self

Converts to this type from the input type.
source§

impl<T> From<u64> for Value<T>
where T: WasmValueType,

source§

fn from(val: u64) -> Self

Converts to this type from the input type.
source§

impl<T: PartialEq> PartialEq for Value<T>

source§

fn eq(&self, other: &Value<T>) -> 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<T> ToString for Value<T>
where T: WasmValueType,

source§

fn to_string(&self) -> String

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

impl<T> TryFrom<Value<T>> for f32
where T: WasmValueType,

§

type Error = &'static str

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

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

Performs the conversion.
source§

impl<T> TryFrom<Value<T>> for f64
where T: WasmValueType,

§

type Error = &'static str

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

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

Performs the conversion.
source§

impl<T> TryFrom<Value<T>> for i32
where T: WasmValueType,

§

type Error = &'static str

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

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

Performs the conversion.
source§

impl<T> TryFrom<Value<T>> for i64
where T: WasmValueType,

§

type Error = &'static str

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

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

Performs the conversion.
source§

impl<T> TryFrom<Value<T>> for u32
where T: WasmValueType,

§

type Error = &'static str

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

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

Performs the conversion.
source§

impl<T> TryFrom<Value<T>> for u64
where T: WasmValueType,

§

type Error = &'static str

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

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

Performs the conversion.
source§

impl<T> StructuralPartialEq for Value<T>

Auto Trait Implementations§

§

impl<T> Freeze for Value<T>
where T: Freeze,

§

impl<T> !RefUnwindSafe for Value<T>

§

impl<T> !Send for Value<T>

§

impl<T> !Sync for Value<T>

§

impl<T> Unpin for Value<T>
where T: Unpin,

§

impl<T> !UnwindSafe for Value<T>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> ArchivePointee for T

§

type ArchivedMetadata = ()

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

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 T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<F, W, T, D> Deserialize<With<T, W>, D> for F
where W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

source§

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, U> Into<U> for T
where 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.

source§

impl<T> Pointee for T

§

type Metadata = ()

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

impl<T> ToOwned for T
where 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 T
where 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 T
where 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.