wasmtime::component

Enum Val

Source
pub enum Val {
Show 22 variants Bool(bool), S8(i8), U8(u8), S16(i16), U16(u16), S32(i32), U32(u32), S64(i64), U64(u64), Float32(f32), Float64(f64), Char(char), String(String), List(Vec<Val>), Record(Vec<(String, Val)>), Tuple(Vec<Val>), Variant(String, Option<Box<Val>>), Enum(String), Option(Option<Box<Val>>), Result(Result<Option<Box<Val>>, Option<Box<Val>>>), Flags(Vec<String>), Resource(ResourceAny),
}
Available on crate features runtime and component-model only.
Expand description

Represents possible runtime values which a component function can either consume or produce

This is a dynamic representation of possible values in the component model. Note that this is not an efficient representation but is instead intended to be a flexible and somewhat convenient representation. The most efficient representation of component model types is to use the bindgen! macro to generate native Rust types with specialized liftings and lowerings.

This type is used in conjunction with Func::call for example if the signature of a component is not statically known ahead of time.

§Equality and Val

This type implements both the Rust PartialEq and Eq traits. This type additionally contains values which are not necessarily easily equated, however, such as floats (Float32 and Float64) and resources. Equality does require that two values have the same type, and then these cases are handled as:

  • Floats are tested if they are “semantically the same” meaning all NaN values are equal to all other NaN values. Additionally zero values must be exactly the same, so positive zero is not equal to negative zero. The primary use case at this time is fuzzing-related equality which this is sufficient for.

  • Resources are tested if their types and indices into the host table are equal. This does not compare the underlying representation so borrows of the same guest resource are not considered equal. This additionally doesn’t go further and test for equality in the guest itself (for example two different heap allocations of Box<u32> can be equal in normal Rust if they contain the same value, but will never be considered equal when compared as Val::Resources).

In general if a strict guarantee about equality is required here it’s recommended to “build your own” as this equality intended for fuzzing Wasmtime may not be suitable for you.

§Component model types and Val

The Val type here does not contain enough information to say what the component model type of a Val is. This is instead more of an AST of sorts. For example the Val::Enum only carries information about a single discriminant, not the entire enumeration or what it’s a discriminant of.

This means that when a Val is passed to Wasmtime, for example as a function parameter when calling a function or as a return value from an host-defined imported function, then it must pass a type-check. Instances of Val are type-checked against what’s required by the component itself.

Variants§

§

Bool(bool)

§

S8(i8)

§

U8(u8)

§

S16(i16)

§

U16(u16)

§

S32(i32)

§

U32(u32)

§

S64(i64)

§

U64(u64)

§

Float32(f32)

§

Float64(f64)

§

Char(char)

§

String(String)

§

List(Vec<Val>)

§

Record(Vec<(String, Val)>)

§

Tuple(Vec<Val>)

§

Variant(String, Option<Box<Val>>)

§

Enum(String)

§

Option(Option<Box<Val>>)

§

Result(Result<Option<Box<Val>>, Option<Box<Val>>>)

§

Flags(Vec<String>)

§

Resource(ResourceAny)

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 PartialEq for Val

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq 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
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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 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> 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.