Enum wasmtime::Val

source ·
pub enum Val {
    I32(i32),
    I64(i64),
    F32(u32),
    F64(u64),
    V128(V128),
    FuncRef(Option<Func>),
    ExternRef(Option<ExternRef>),
}
Expand description

Possible runtime values that a WebAssembly module can either consume or produce.

Variants§

§

I32(i32)

A 32-bit integer

§

I64(i64)

A 64-bit integer

§

F32(u32)

A 32-bit float.

Note that the raw bits of the float are stored here, and you can use f32::from_bits to create an f32 value.

§

F64(u64)

A 64-bit float.

Note that the raw bits of the float are stored here, and you can use f64::from_bits to create an f64 value.

§

V128(V128)

A 128-bit number

§

FuncRef(Option<Func>)

A first-class reference to a WebAssembly function.

FuncRef(None) is the null function reference, created by ref.null func in Wasm.

§

ExternRef(Option<ExternRef>)

An externref value which can hold opaque data to the Wasm instance itself.

ExternRef(None) is the null external reference, created by ref.null extern in Wasm.

Implementations§

source§

impl Val

source

pub fn null() -> Val

Returns a null externref value.

source

pub fn ty(&self) -> ValType

Returns the corresponding ValType for this Val.

source

pub unsafe fn to_raw(&self, store: impl AsContextMut) -> ValRaw

Convenience method to convert this Val into a ValRaw.

Unsafety

This method is unsafe for the reasons that ExternRef::to_raw and Func::to_raw are unsafe.

source

pub unsafe fn from_raw( store: impl AsContextMut, raw: ValRaw, ty: ValType ) -> Val

Convenience method to convert a ValRaw into a Val.

Unsafety

This method is unsafe for the reasons that ExternRef::from_raw and Func::from_raw are unsafe. Additionaly there’s no guarantee otherwise that raw should have the type ty specified.

source

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

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

source

pub fn unwrap_i32(&self) -> i32

Returns the underlying value of this Val, 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 Val, returning None if it is not the correct type.

source

pub fn unwrap_i64(&self) -> i64

Returns the underlying value of this Val, 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 Val, returning None if it is not the correct type.

source

pub fn unwrap_f32(&self) -> f32

Returns the underlying value of this Val, 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 Val, returning None if it is not the correct type.

source

pub fn unwrap_f64(&self) -> f64

Returns the underlying value of this Val, panicking if it’s the wrong type.

Panics

Panics if self is not of the right type.

source

pub fn funcref(&self) -> Option<Option<&Func>>

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

source

pub fn unwrap_funcref(&self) -> Option<&Func>

Returns the underlying value of this Val, panicking if it’s the wrong type.

Panics

Panics if self is not of the right type.

source

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

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

source

pub fn unwrap_v128(&self) -> V128

Returns the underlying value of this Val, 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 externref value of this Val.

If this is not an externref, then None is returned.

If this is a null externref, then Some(None) is returned.

If this is a non-null externref, then Some(Some(..)) is returned.

source

pub fn unwrap_externref(&self) -> Option<ExternRef>

Returns the underlying externref value of this Val, panicking if it’s the wrong type.

If this is a null externref, then None is returned.

If this is a non-null externref, then Some(..) is returned.

Panics

Panics if self is not a (nullable) externref.

Trait Implementations§

source§

impl Clone for Val

source§

fn clone(&self) -> Val

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 Val

source§

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

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

impl From<ExternRef> for Val

source§

fn from(val: ExternRef) -> Val

Converts to this type from the input type.
source§

impl From<Func> for Val

source§

fn from(val: Func) -> Val

Converts to this type from the input type.
source§

impl From<Option<ExternRef>> for Val

source§

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

Converts to this type from the input type.
source§

impl From<Option<Func>> for Val

source§

fn from(val: Option<Func>) -> Val

Converts to this type from the input type.
source§

impl From<V128> for Val

source§

fn from(val: V128) -> Val

Converts to this type from the input type.
source§

impl From<f32> for Val

source§

fn from(val: f32) -> Val

Converts to this type from the input type.
source§

impl From<f64> for Val

source§

fn from(val: f64) -> Val

Converts to this type from the input type.
source§

impl From<i32> for Val

source§

fn from(val: i32) -> Val

Converts to this type from the input type.
source§

impl From<i64> for Val

source§

fn from(val: i64) -> Val

Converts to this type from the input type.
source§

impl From<u128> for Val

source§

fn from(val: u128) -> Val

Converts to this type from the input type.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Val

§

impl Send for Val

§

impl Sync for Val

§

impl Unpin for Val

§

impl !UnwindSafe for Val

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
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
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Pointable for T

§

const ALIGN: usize = _

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

impl<T> Same for T

§

type Output = T

Should always be 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.