wasm_wave::wasm

Trait WasmValue

source
pub trait WasmValue: Clone + Sized {
    type Type: WasmType;

Show 43 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_float32(val: f32) -> Self { ... } fn make_float64(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 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_float32(&self) -> f32 { ... } fn unwrap_float64(&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>> + '_> { ... }
}
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§

source

type Type: WasmType

A type representing types of these values.

Required Methods§

source

fn kind(&self) -> WasmTypeKind

The kind of type of this value.

Provided Methods§

source

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

source

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

source

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

source

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

source

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

source

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

source

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

source

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

source

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

source

fn make_float32(val: f32) -> Self

Returns a new WasmValue of the given type.

The Rust f32 type has many distinct NaN bitpatterns, however the component-model float32 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).

source

fn make_float64(val: f64) -> Self

Returns a new WasmValue of the given type.

The Rust f64 type has many distinct NaN bitpatterns, however the component-model float64 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).

source

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

source

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

source

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

source

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

source

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

source

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

source

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

source

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

source

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

source

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

source

fn unwrap_bool(&self) -> bool

Returns the underlying value of the WasmValue, panicing if it’s the wrong type.

§Panics

Panics if self is not of the right type.

source

fn unwrap_s8(&self) -> i8

Returns the underlying value of the WasmValue, panicing if it’s the wrong type.

§Panics

Panics if self is not of the right type.

source

fn unwrap_s16(&self) -> i16

Returns the underlying value of the WasmValue, panicing if it’s the wrong type.

§Panics

Panics if self is not of the right type.

source

fn unwrap_s32(&self) -> i32

Returns the underlying value of the WasmValue, panicing if it’s the wrong type.

§Panics

Panics if self is not of the right type.

source

fn unwrap_s64(&self) -> i64

Returns the underlying value of the WasmValue, panicing if it’s the wrong type.

§Panics

Panics if self is not of the right type.

source

fn unwrap_u8(&self) -> u8

Returns the underlying value of the WasmValue, panicing if it’s the wrong type.

§Panics

Panics if self is not of the right type.

source

fn unwrap_u16(&self) -> u16

Returns the underlying value of the WasmValue, panicing if it’s the wrong type.

§Panics

Panics if self is not of the right type.

source

fn unwrap_u32(&self) -> u32

Returns the underlying value of the WasmValue, panicing if it’s the wrong type.

§Panics

Panics if self is not of the right type.

source

fn unwrap_u64(&self) -> u64

Returns the underlying value of the WasmValue, panicing if it’s the wrong type.

§Panics

Panics if self is not of the right type.

source

fn unwrap_float32(&self) -> f32

Returns the underlying value of the WasmValue, panicing if it’s the wrong type.

The Rust f32 type has many distinct NaN bitpatterns, however the component-model float64 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.

source

fn unwrap_float64(&self) -> f64

Returns the underlying value of the WasmValue, panicing if it’s the wrong type.

The Rust f64 type has many distinct NaN bitpatterns, however the component-model float64 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.

source

fn unwrap_char(&self) -> char

Returns the underlying value of the WasmValue, panicing if it’s the wrong type.

§Panics

Panics if self is not of the right type.

source

fn unwrap_string(&self) -> Cow<'_, str>

Returns the underlying value of the WasmValue, panicing if it’s the wrong type.

§Panics

Panics if self is not of the right type.

source

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.

source

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.

source

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.

source

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.

source

fn unwrap_enum(&self) -> Cow<'_, str>

Returns the case name of the enum.

§Panics

Panics if self is not of the right type.

source

fn unwrap_option(&self) -> Option<Cow<'_, Self>>

Returns the optional WasmValue.

§Panics

Panics if self is not of the right type.

source

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.

source

fn unwrap_flags(&self) -> Box<dyn Iterator<Item = Cow<'_, str>> + '_>

Returns an iterator of the names of the flags WasmValue.

§Panics

Panics if self is not of the right type.

Object Safety§

This trait is not object safe.

Implementors§