Trait WasmValue
pub trait WasmValue: Sized + Clone {
type Type: WasmType;
Show 45 methods
// Required method
fn kind(&self) -> WasmTypeKind;
// Provided methods
fn make_bool(val: bool) -> Self { ... }
fn make_s8(val: i8) -> Self { ... }
fn make_s16(val: i16) -> Self { ... }
fn make_s32(val: i32) -> Self { ... }
fn make_s64(val: i64) -> Self { ... }
fn make_u8(val: u8) -> Self { ... }
fn make_u16(val: u16) -> Self { ... }
fn make_u32(val: u32) -> Self { ... }
fn make_u64(val: u64) -> Self { ... }
fn make_f32(val: f32) -> Self { ... }
fn make_f64(val: f64) -> Self { ... }
fn make_char(val: char) -> Self { ... }
fn make_string(val: Cow<'_, str>) -> Self { ... }
fn make_list(
ty: &Self::Type,
vals: impl IntoIterator<Item = Self>,
) -> Result<Self, WasmValueError> { ... }
fn make_record<'a>(
ty: &Self::Type,
fields: impl IntoIterator<Item = (&'a str, Self)>,
) -> Result<Self, WasmValueError> { ... }
fn make_tuple(
ty: &Self::Type,
vals: impl IntoIterator<Item = Self>,
) -> Result<Self, WasmValueError> { ... }
fn make_variant(
ty: &Self::Type,
case: &str,
val: Option<Self>,
) -> Result<Self, WasmValueError> { ... }
fn make_enum(ty: &Self::Type, case: &str) -> Result<Self, WasmValueError> { ... }
fn make_option(
ty: &Self::Type,
val: Option<Self>,
) -> Result<Self, WasmValueError> { ... }
fn make_result(
ty: &Self::Type,
val: Result<Option<Self>, Option<Self>>,
) -> Result<Self, WasmValueError> { ... }
fn make_flags<'a>(
ty: &Self::Type,
names: impl IntoIterator<Item = &'a str>,
) -> Result<Self, WasmValueError> { ... }
fn make_map(
ty: &Self::Type,
entries: impl IntoIterator<Item = (Self, Self)>,
) -> Result<Self, WasmValueError> { ... }
fn unwrap_bool(&self) -> bool { ... }
fn unwrap_s8(&self) -> i8 { ... }
fn unwrap_s16(&self) -> i16 { ... }
fn unwrap_s32(&self) -> i32 { ... }
fn unwrap_s64(&self) -> i64 { ... }
fn unwrap_u8(&self) -> u8 { ... }
fn unwrap_u16(&self) -> u16 { ... }
fn unwrap_u32(&self) -> u32 { ... }
fn unwrap_u64(&self) -> u64 { ... }
fn unwrap_f32(&self) -> f32 { ... }
fn unwrap_f64(&self) -> f64 { ... }
fn unwrap_char(&self) -> char { ... }
fn unwrap_string(&self) -> Cow<'_, str> { ... }
fn unwrap_list(&self) -> Box<dyn Iterator<Item = Cow<'_, Self>> + '_> { ... }
fn unwrap_record(
&self,
) -> Box<dyn Iterator<Item = (Cow<'_, str>, Cow<'_, Self>)> + '_> { ... }
fn unwrap_tuple(&self) -> Box<dyn Iterator<Item = Cow<'_, Self>> + '_> { ... }
fn unwrap_variant(&self) -> (Cow<'_, str>, Option<Cow<'_, Self>>) { ... }
fn unwrap_enum(&self) -> Cow<'_, str> { ... }
fn unwrap_option(&self) -> Option<Cow<'_, Self>> { ... }
fn unwrap_result(
&self,
) -> Result<Option<Cow<'_, Self>>, Option<Cow<'_, Self>>> { ... }
fn unwrap_flags(&self) -> Box<dyn Iterator<Item = Cow<'_, str>> + '_> { ... }
fn unwrap_map(
&self,
) -> Box<dyn Iterator<Item = (Cow<'_, Self>, Cow<'_, Self>)> + '_> { ... }
}Expand description
The WasmValue trait may be implemented to represent values to be
(de)serialized with WAVE, notably value::Value.
The wasmtime crate provides an impl for wasmtime::component::Val.
The make_* and unwrap_* methods should be called only for corresponding
WasmTypeKinds.
Required Associated Types§
Required Methods§
fn kind(&self) -> WasmTypeKind
fn kind(&self) -> WasmTypeKind
The kind of type of this value.
Provided Methods§
fn make_bool(val: bool) -> Self
fn make_bool(val: bool) -> Self
Returns a new WasmValue of the given type.
§Panics
Panics if the type is not implemented (the trait default).
fn make_s8(val: i8) -> Self
fn make_s8(val: i8) -> Self
Returns a new WasmValue of the given type.
§Panics
Panics if the type is not implemented (the trait default).
fn make_s16(val: i16) -> Self
fn make_s16(val: i16) -> Self
Returns a new WasmValue of the given type.
§Panics
Panics if the type is not implemented (the trait default).
fn make_s32(val: i32) -> Self
fn make_s32(val: i32) -> Self
Returns a new WasmValue of the given type.
§Panics
Panics if the type is not implemented (the trait default).
fn make_s64(val: i64) -> Self
fn make_s64(val: i64) -> Self
Returns a new WasmValue of the given type.
§Panics
Panics if the type is not implemented (the trait default).
fn make_u8(val: u8) -> Self
fn make_u8(val: u8) -> Self
Returns a new WasmValue of the given type.
§Panics
Panics if the type is not implemented (the trait default).
fn make_u16(val: u16) -> Self
fn make_u16(val: u16) -> Self
Returns a new WasmValue of the given type.
§Panics
Panics if the type is not implemented (the trait default).
fn make_u32(val: u32) -> Self
fn make_u32(val: u32) -> Self
Returns a new WasmValue of the given type.
§Panics
Panics if the type is not implemented (the trait default).
fn make_u64(val: u64) -> Self
fn make_u64(val: u64) -> Self
Returns a new WasmValue of the given type.
§Panics
Panics if the type is not implemented (the trait default).
fn make_f32(val: f32) -> Self
fn make_f32(val: f32) -> Self
Returns a new WasmValue of the given type.
The Rust f32 type has many distinct NaN bitpatterns, however the
component-model f32 type only has a single NaN value, so this
function does not preserve NaN bitpatterns.
§Panics
Panics if the type is not implemented (the trait default).
fn make_f64(val: f64) -> Self
fn make_f64(val: f64) -> Self
Returns a new WasmValue of the given type.
The Rust f64 type has many distinct NaN bitpatterns, however the
component-model f64 type only has a single NaN value, so this
function does not preserve NaN bitpatterns.
§Panics
Panics if the type is not implemented (the trait default).
fn make_char(val: char) -> Self
fn make_char(val: char) -> Self
Returns a new WasmValue of the given type.
§Panics
Panics if the type is not implemented (the trait default).
fn make_string(val: Cow<'_, str>) -> Self
fn make_string(val: Cow<'_, str>) -> Self
Returns a new WasmValue of the given type.
§Panics
Panics if the type is not implemented (the trait default).
fn make_list(
ty: &Self::Type,
vals: impl IntoIterator<Item = Self>,
) -> Result<Self, WasmValueError>
fn make_list( ty: &Self::Type, vals: impl IntoIterator<Item = Self>, ) -> Result<Self, WasmValueError>
Returns a new WasmValue of the given type.
§Panics
Panics if the type is not implemented (the trait default).
fn make_record<'a>(
ty: &Self::Type,
fields: impl IntoIterator<Item = (&'a str, Self)>,
) -> Result<Self, WasmValueError>
fn make_record<'a>( ty: &Self::Type, fields: impl IntoIterator<Item = (&'a str, Self)>, ) -> Result<Self, WasmValueError>
Returns a new WasmValue of the given type.
The fields provided by fields are not necessarily sorted; the callee
should perform sorting itself if needed.
§Panics
Panics if the type is not implemented (the trait default).
fn make_tuple(
ty: &Self::Type,
vals: impl IntoIterator<Item = Self>,
) -> Result<Self, WasmValueError>
fn make_tuple( ty: &Self::Type, vals: impl IntoIterator<Item = Self>, ) -> Result<Self, WasmValueError>
Returns a new WasmValue of the given type.
§Panics
Panics if the type is not implemented (the trait default).
fn make_variant(
ty: &Self::Type,
case: &str,
val: Option<Self>,
) -> Result<Self, WasmValueError>
fn make_variant( ty: &Self::Type, case: &str, val: Option<Self>, ) -> Result<Self, WasmValueError>
Returns a new WasmValue of the given type.
§Panics
Panics if the type is not implemented (the trait default).
fn make_enum(ty: &Self::Type, case: &str) -> Result<Self, WasmValueError>
fn make_enum(ty: &Self::Type, case: &str) -> Result<Self, WasmValueError>
Returns a new WasmValue of the given type.
§Panics
Panics if the type is not implemented (the trait default).
fn make_option(
ty: &Self::Type,
val: Option<Self>,
) -> Result<Self, WasmValueError>
fn make_option( ty: &Self::Type, val: Option<Self>, ) -> Result<Self, WasmValueError>
Returns a new WasmValue of the given type.
§Panics
Panics if the type is not implemented (the trait default).
fn make_result(
ty: &Self::Type,
val: Result<Option<Self>, Option<Self>>,
) -> Result<Self, WasmValueError>
fn make_result( ty: &Self::Type, val: Result<Option<Self>, Option<Self>>, ) -> Result<Self, WasmValueError>
Returns a new WasmValue of the given type.
§Panics
Panics if the type is not implemented (the trait default).
fn make_flags<'a>(
ty: &Self::Type,
names: impl IntoIterator<Item = &'a str>,
) -> Result<Self, WasmValueError>
fn make_flags<'a>( ty: &Self::Type, names: impl IntoIterator<Item = &'a str>, ) -> Result<Self, WasmValueError>
Returns a new WasmValue of the given type.
The strings provided by names are not necessarily sorted; the callee
should perform sorting itself if needed.
§Panics
Panics if the type is not implemented (the trait default).
fn make_map(
ty: &Self::Type,
entries: impl IntoIterator<Item = (Self, Self)>,
) -> Result<Self, WasmValueError>
fn make_map( ty: &Self::Type, entries: impl IntoIterator<Item = (Self, Self)>, ) -> Result<Self, WasmValueError>
Returns a new WasmValue of the given type.
The key-value pairs provided by entries are in their encoded order,
which the callee should preserve if it can. When parsing, keys are
unique: duplicate keys have already been merged, keeping the last
value at the position where the key first appears.
§Panics
Panics if the type is not implemented (the trait default).
fn unwrap_bool(&self) -> bool
fn unwrap_bool(&self) -> bool
Returns the underlying value of the WasmValue, panicking if it’s the wrong type.
§Panics
Panics if self is not of the right type.
fn unwrap_s8(&self) -> i8
fn unwrap_s8(&self) -> i8
Returns the underlying value of the WasmValue, panicking if it’s the wrong type.
§Panics
Panics if self is not of the right type.
fn unwrap_s16(&self) -> i16
fn unwrap_s16(&self) -> i16
Returns the underlying value of the WasmValue, panicking if it’s the wrong type.
§Panics
Panics if self is not of the right type.
fn unwrap_s32(&self) -> i32
fn unwrap_s32(&self) -> i32
Returns the underlying value of the WasmValue, panicking if it’s the wrong type.
§Panics
Panics if self is not of the right type.
fn unwrap_s64(&self) -> i64
fn unwrap_s64(&self) -> i64
Returns the underlying value of the WasmValue, panicking if it’s the wrong type.
§Panics
Panics if self is not of the right type.
fn unwrap_u8(&self) -> u8
fn unwrap_u8(&self) -> u8
Returns the underlying value of the WasmValue, panicking if it’s the wrong type.
§Panics
Panics if self is not of the right type.
fn unwrap_u16(&self) -> u16
fn unwrap_u16(&self) -> u16
Returns the underlying value of the WasmValue, panicking if it’s the wrong type.
§Panics
Panics if self is not of the right type.
fn unwrap_u32(&self) -> u32
fn unwrap_u32(&self) -> u32
Returns the underlying value of the WasmValue, panicking if it’s the wrong type.
§Panics
Panics if self is not of the right type.
fn unwrap_u64(&self) -> u64
fn unwrap_u64(&self) -> u64
Returns the underlying value of the WasmValue, panicking if it’s the wrong type.
§Panics
Panics if self is not of the right type.
fn unwrap_f32(&self) -> f32
fn unwrap_f32(&self) -> f32
Returns the underlying value of the WasmValue, panicking if it’s the wrong type.
The Rust f32 type has many distinct NaN bitpatterns, however the
component-model f64 type only has a single NaN value, so this
function does not preserve NaN bitpatterns.
§Panics
Panics if self is not of the right type.
fn unwrap_f64(&self) -> f64
fn unwrap_f64(&self) -> f64
Returns the underlying value of the WasmValue, panicking if it’s the wrong type.
The Rust f64 type has many distinct NaN bitpatterns, however the
component-model f64 type only has a single NaN value, so this
function does not preserve NaN bitpatterns.
§Panics
Panics if self is not of the right type.
fn unwrap_char(&self) -> char
fn unwrap_char(&self) -> char
Returns the underlying value of the WasmValue, panicking if it’s the wrong type.
§Panics
Panics if self is not of the right type.
fn unwrap_string(&self) -> Cow<'_, str>
fn unwrap_string(&self) -> Cow<'_, str>
Returns the underlying value of the WasmValue, panicking if it’s the wrong type.
§Panics
Panics if self is not of the right type.
fn unwrap_list(&self) -> Box<dyn Iterator<Item = Cow<'_, Self>> + '_>
fn unwrap_list(&self) -> Box<dyn Iterator<Item = Cow<'_, Self>> + '_>
Returns an iterator of the element Vals of the list.
§Panics
Panics if self is not of the right type.
fn unwrap_record(
&self,
) -> Box<dyn Iterator<Item = (Cow<'_, str>, Cow<'_, Self>)> + '_>
fn unwrap_record( &self, ) -> Box<dyn Iterator<Item = (Cow<'_, str>, Cow<'_, Self>)> + '_>
Returns an iterator of the field names and Vals of the record.
§Panics
Panics if self is not of the right type.
fn unwrap_tuple(&self) -> Box<dyn Iterator<Item = Cow<'_, Self>> + '_>
fn unwrap_tuple(&self) -> Box<dyn Iterator<Item = Cow<'_, Self>> + '_>
Returns an iterator of the field Vals of the tuple.
§Panics
Panics if self is not of the right type.
fn unwrap_variant(&self) -> (Cow<'_, str>, Option<Cow<'_, Self>>)
fn unwrap_variant(&self) -> (Cow<'_, str>, Option<Cow<'_, Self>>)
Returns the variant case name and optional payload WasmValue of the variant.
§Panics
Panics if self is not of the right type.
fn unwrap_enum(&self) -> Cow<'_, str>
fn unwrap_enum(&self) -> Cow<'_, str>
fn unwrap_option(&self) -> Option<Cow<'_, Self>>
fn unwrap_option(&self) -> Option<Cow<'_, Self>>
fn unwrap_result(&self) -> Result<Option<Cow<'_, Self>>, Option<Cow<'_, Self>>>
fn unwrap_result(&self) -> Result<Option<Cow<'_, Self>>, Option<Cow<'_, Self>>>
Returns Ok() or Err() with the optional payload WasmValue.
§Panics
Panics if self is not of the right type.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".