wiggle::wasmtime_crate

Enum Val

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

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

Note that we inline the enum Ref { ... } variants into enum Val { ... } here as a size optimization.

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

§

ExternRef(Option<Rooted<ExternRef>>)

An external reference.

§

AnyRef(Option<Rooted<AnyRef>>)

An internal reference.

Implementations§

§

impl Val

pub fn null_ref(heap_type: &HeapType) -> Val

Returns the null reference for the given heap type.

pub const fn null_func_ref() -> Val

Returns the null function reference value.

The return value has type (ref null nofunc) aka nullfuncref and is a subtype of all function references.

pub const fn null_extern_ref() -> Val

Returns the null function reference value.

The return value has type (ref null extern) aka nullexternref and is a subtype of all external references.

pub const fn null_any_ref() -> Val

Returns the null function reference value.

The return value has type (ref null any) aka nullref and is a subtype of all internal references.

pub fn default_for_ty(ty: &ValType) -> Option<Val>

Returns the default value for the given type, if any exists.

Returns None if there is no default value for the given type (for example, non-nullable reference types do not have a default value).

pub fn ty(&self, store: impl AsContext) -> Result<ValType, Error>

Returns the corresponding ValType for this Val.

§Errors

Returns an error if this value is a GC reference that has since been unrooted.

§Panics

Panics if this value is associated with a different store.

pub fn matches_ty( &self, store: impl AsContext, ty: &ValType, ) -> Result<bool, Error>

Does this value match the given type?

Returns an error is an underlying Rooted has been unrooted.

§Panics

Panics if this value is not associated with the given store.

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

Convenience method to convert this Val into a ValRaw.

Returns an error if this value is a GC reference and the GC reference has been unrooted.

§Unsafety

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

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. Additionally there’s no guarantee otherwise that raw should have the type ty specified.

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

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

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.

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

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

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.

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

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

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.

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

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

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.

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

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

pub fn unwrap_func_ref(&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.

pub fn extern_ref(&self) -> Option<Option<&Rooted<ExternRef>>>

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

pub fn unwrap_extern_ref(&self) -> Option<&Rooted<ExternRef>>

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

§Panics

Panics if self is not of the right type.

pub fn any_ref(&self) -> Option<Option<&Rooted<AnyRef>>>

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

pub fn unwrap_any_ref(&self) -> Option<&Rooted<AnyRef>>

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

§Panics

Panics if self is not of the right type.

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

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

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.

pub fn ref_(self) -> Option<Ref>

Get this value’s underlying reference, if any.

pub fn externref(&self) -> Option<Option<&Rooted<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.

pub fn unwrap_externref(&self) -> Option<&Rooted<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.

pub fn anyref(&self) -> Option<Option<&Rooted<AnyRef>>>

Attempt to access the underlying anyref value of this Val.

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

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

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

pub fn unwrap_anyref(&self) -> Option<&Rooted<AnyRef>>

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

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

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

§Panics

Panics if self is not a (nullable) anyref.

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

Attempt to access the underlying funcref value of this Val.

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

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

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

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

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

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

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

§Panics

Panics if self is not a (nullable) funcref.

Trait Implementations§

§

impl Clone for Val

§

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
§

impl Debug for Val

§

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

Formats the value using the given formatter. Read more
§

impl From<Func> for Val

§

fn from(val: Func) -> Val

Converts to this type from the input type.
§

impl From<Option<Func>> for Val

§

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

Converts to this type from the input type.
§

impl From<Option<Rooted<AnyRef>>> for Val

§

fn from(val: Option<Rooted<AnyRef>>) -> Val

Converts to this type from the input type.
§

impl From<Option<Rooted<ArrayRef>>> for Val

§

fn from(val: Option<Rooted<ArrayRef>>) -> Val

Converts to this type from the input type.
§

impl From<Option<Rooted<ExternRef>>> for Val

§

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

Converts to this type from the input type.
§

impl From<Option<Rooted<StructRef>>> for Val

§

fn from(val: Option<Rooted<StructRef>>) -> Val

Converts to this type from the input type.
§

impl From<Ref> for Val

§

fn from(val: Ref) -> Val

Converts to this type from the input type.
§

impl From<Rooted<AnyRef>> for Val

§

fn from(val: Rooted<AnyRef>) -> Val

Converts to this type from the input type.
§

impl From<Rooted<ArrayRef>> for Val

§

fn from(val: Rooted<ArrayRef>) -> Val

Converts to this type from the input type.
§

impl From<Rooted<ExternRef>> for Val

§

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

Converts to this type from the input type.
§

impl From<Rooted<StructRef>> for Val

§

fn from(val: Rooted<StructRef>) -> Val

Converts to this type from the input type.
§

impl From<V128> for Val

§

fn from(val: V128) -> Val

Converts to this type from the input type.
§

impl From<f32> for Val

§

fn from(val: f32) -> Val

Converts to this type from the input type.
§

impl From<f64> for Val

§

fn from(val: f64) -> Val

Converts to this type from the input type.
§

impl From<i32> for Val

§

fn from(val: i32) -> Val

Converts to this type from the input type.
§

impl From<i64> for Val

§

fn from(val: i64) -> Val

Converts to this type from the input type.
§

impl From<u128> for Val

§

fn from(val: u128) -> Val

Converts to this type from the input type.
§

impl Copy for Val

Auto Trait Implementations§

§

impl Freeze for Val

§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
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 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

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

Source§

type Pointer = u32

Source§

fn debug( pointer: <T as Pointee>::Pointer, f: &mut Formatter<'_>, ) -> Result<(), Error>

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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

Source§

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

Source§

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