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 asVal::Resource
s).
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 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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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