wiggle::wasmtime_crate::component

Enum Val

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),
}
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§

§

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

§

fn eq(&self, other: &Val) -> 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.
§

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

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