use alloc::{borrow::Cow, boxed::Box};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[allow(missing_docs)]
#[non_exhaustive]
pub enum WasmTypeKind {
Bool,
S8,
S16,
S32,
S64,
U8,
U16,
U32,
U64,
F32,
F64,
Char,
String,
List,
FixedLengthList,
Record,
Tuple,
Variant,
Enum,
Option,
Result,
Flags,
#[doc(hidden)]
Unsupported,
}
impl core::fmt::Display for WasmTypeKind {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str(match self {
WasmTypeKind::Bool => "bool",
WasmTypeKind::S8 => "s8",
WasmTypeKind::S16 => "s16",
WasmTypeKind::S32 => "s32",
WasmTypeKind::S64 => "s64",
WasmTypeKind::U8 => "u8",
WasmTypeKind::U16 => "u16",
WasmTypeKind::U32 => "u32",
WasmTypeKind::U64 => "u64",
WasmTypeKind::F32 => "f32",
WasmTypeKind::F64 => "f64",
WasmTypeKind::Char => "char",
WasmTypeKind::String => "string",
WasmTypeKind::List => "list",
WasmTypeKind::FixedLengthList => "list<_,N>",
WasmTypeKind::Record => "record",
WasmTypeKind::Tuple => "tuple",
WasmTypeKind::Variant => "variant",
WasmTypeKind::Enum => "enum",
WasmTypeKind::Option => "option",
WasmTypeKind::Result => "result",
WasmTypeKind::Flags => "flags",
WasmTypeKind::Unsupported => "<<UNSUPPORTED>>",
})
}
}
pub trait WasmType: Clone + Sized {
fn kind(&self) -> WasmTypeKind;
fn list_element_type(&self) -> Option<Self> {
unimplemented!()
}
fn record_fields(&self) -> Box<dyn Iterator<Item = (Cow<'_, str>, Self)> + '_> {
unimplemented!()
}
fn tuple_element_types(&self) -> Box<dyn Iterator<Item = Self> + '_> {
unimplemented!()
}
fn variant_cases(&self) -> Box<dyn Iterator<Item = (Cow<'_, str>, Option<Self>)> + '_> {
unimplemented!()
}
fn enum_cases(&self) -> Box<dyn Iterator<Item = Cow<'_, str>> + '_> {
unimplemented!()
}
fn option_some_type(&self) -> Option<Self> {
unimplemented!()
}
fn result_types(&self) -> Option<(Option<Self>, Option<Self>)> {
unimplemented!()
}
fn flags_names(&self) -> Box<dyn Iterator<Item = Cow<'_, str>> + '_> {
unimplemented!()
}
}
macro_rules! maybe_unwrap_type {
($ty:expr, $case:path) => {
match $ty {
$case(v) => Some(v),
_ => None,
}
};
}
pub(crate) use maybe_unwrap_type;