diff options
| author | Henry Gressmann <mail@henrygressmann.de> | 2025-05-06 21:36:25 +0200 |
|---|---|---|
| committer | Henry Gressmann <mail@henrygressmann.de> | 2025-05-06 21:36:25 +0200 |
| commit | f9f760f487cfb08aa7992439bf748f7dcd46466b (patch) | |
| tree | 8d08b92b30eab6e4b107ecfc2fd65a1f3603f411 /crates/types | |
| parent | 0f3581ef8fdb55ad21fdfd132eaefadaec242f85 (diff) | |
chore: cleanup
Signed-off-by: Henry Gressmann <mail@henrygressmann.de>
Diffstat (limited to 'crates/types')
| -rw-r--r-- | crates/types/Cargo.toml | 2 | ||||
| -rw-r--r-- | crates/types/src/archive.rs | 10 | ||||
| -rw-r--r-- | crates/types/src/instructions.rs | 2 | ||||
| -rw-r--r-- | crates/types/src/lib.rs | 26 | ||||
| -rw-r--r-- | crates/types/src/value.rs | 28 |
5 files changed, 35 insertions, 33 deletions
diff --git a/crates/types/Cargo.toml b/crates/types/Cargo.toml index fda8a86..b986c2a 100644 --- a/crates/types/Cargo.toml +++ b/crates/types/Cargo.toml @@ -7,6 +7,8 @@ license.workspace=true authors.workspace=true repository.workspace=true rust-version.workspace=true +keywords.workspace=true +categories.workspace=true [dependencies] log={workspace=true, optional=true} diff --git a/crates/types/src/archive.rs b/crates/types/src/archive.rs index b190d43..7d52049 100644 --- a/crates/types/src/archive.rs +++ b/crates/types/src/archive.rs @@ -34,10 +34,10 @@ pub enum TwasmError { impl Display for TwasmError { fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { match self { - TwasmError::InvalidMagic => write!(f, "Invalid twasm: invalid magic number"), - TwasmError::InvalidVersion => write!(f, "Invalid twasm: invalid version"), - TwasmError::InvalidPadding => write!(f, "Invalid twasm: invalid padding"), - TwasmError::InvalidArchive(e) => write!(f, "Invalid twasm: {e}"), + Self::InvalidMagic => write!(f, "Invalid twasm: invalid magic number"), + Self::InvalidVersion => write!(f, "Invalid twasm: invalid version"), + Self::InvalidPadding => write!(f, "Invalid twasm: invalid padding"), + Self::InvalidArchive(e) => write!(f, "Invalid twasm: {e}"), } } } @@ -49,7 +49,7 @@ impl core::error::Error for TwasmError {} impl TinyWasmModule { /// Creates a `TinyWasmModule` from a slice of bytes. - pub fn from_twasm(wasm: &[u8]) -> Result<TinyWasmModule, TwasmError> { + pub fn from_twasm(wasm: &[u8]) -> Result<Self, TwasmError> { let len = validate_magic(wasm)?; postcard::from_bytes(&wasm[len..]).map_err(TwasmError::InvalidArchive) diff --git a/crates/types/src/instructions.rs b/crates/types/src/instructions.rs index 9db5ed5..aa57dfa 100644 --- a/crates/types/src/instructions.rs +++ b/crates/types/src/instructions.rs @@ -2,7 +2,7 @@ use super::{FuncAddr, GlobalAddr, LabelAddr, LocalAddr, TableAddr, TypeAddr, Val use crate::{ConstIdx, DataAddr, ElemAddr, ExternAddr, MemAddr}; /// Represents a memory immediate in a WebAssembly memory instruction. -#[derive(Debug, Copy, Clone, PartialEq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] pub struct MemoryArg([u8; 12]); diff --git a/crates/types/src/lib.rs b/crates/types/src/lib.rs index 470c631..c34b705 100644 --- a/crates/types/src/lib.rs +++ b/crates/types/src/lib.rs @@ -119,7 +119,7 @@ pub struct TinyWasmModule { /// A WebAssembly External Kind. /// /// See <https://webassembly.github.io/spec/core/syntax/types.html#external-types> -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] pub enum ExternalKind { /// A WebAssembly Function. @@ -191,14 +191,14 @@ impl ExternVal { /// The type of a WebAssembly Function. /// /// See <https://webassembly.github.io/spec/core/syntax/types.html#function-types> -#[derive(Debug, Clone, PartialEq, Default)] +#[derive(Debug, Clone, PartialEq, Eq, Default)] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] pub struct FuncType { pub params: Box<[ValType]>, pub results: Box<[ValType]>, } -#[derive(Debug, Default, Clone, Copy, PartialEq)] +#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] pub struct ValueCounts { pub c32: u32, @@ -207,7 +207,7 @@ pub struct ValueCounts { pub cref: u32, } -#[derive(Debug, Default, Clone, Copy, PartialEq)] +#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] pub struct ValueCountsSmall { pub c32: u16, @@ -218,7 +218,7 @@ pub struct ValueCountsSmall { impl<'a, T: IntoIterator<Item = &'a ValType>> From<T> for ValueCounts { fn from(types: T) -> Self { - let mut counts = ValueCounts::default(); + let mut counts = Self::default(); for ty in types { match ty { ValType::I32 | ValType::F32 => counts.c32 += 1, @@ -233,7 +233,7 @@ impl<'a, T: IntoIterator<Item = &'a ValType>> From<T> for ValueCounts { impl<'a, T: IntoIterator<Item = &'a ValType>> From<T> for ValueCountsSmall { fn from(types: T) -> Self { - let mut counts = ValueCountsSmall::default(); + let mut counts = Self::default(); for ty in types { match ty { ValType::I32 | ValType::F32 => counts.c32 += 1, @@ -256,14 +256,14 @@ pub struct WasmFunction { pub ty: FuncType, } -#[derive(Debug, Clone, PartialEq, Default)] +#[derive(Debug, Clone, PartialEq, Eq, Default)] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] pub struct WasmFunctionData { pub v128_constants: Box<[i128]>, } /// A WebAssembly Module Export -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] pub struct Export { /// The name of the export. @@ -281,14 +281,14 @@ pub struct Global { pub init: ConstInstruction, } -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] pub struct GlobalType { pub mutable: bool, pub ty: ValType, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] pub struct TableType { pub element_type: ValType, @@ -307,7 +307,7 @@ impl TableType { } /// Represents a memory's type. -#[derive(Debug, Copy, Clone, PartialEq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] pub struct MemoryType { arch: MemoryArch, @@ -353,7 +353,7 @@ pub enum MemoryArch { I64, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] pub struct Import { pub module: Box<str>, @@ -361,7 +361,7 @@ pub struct Import { pub kind: ImportKind, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] pub enum ImportKind { Function(TypeAddr), diff --git a/crates/types/src/value.rs b/crates/types/src/value.rs index b68836b..22bb4eb 100644 --- a/crates/types/src/value.rs +++ b/crates/types/src/value.rs @@ -23,14 +23,14 @@ pub enum WasmValue { RefFunc(FuncRef), } -#[derive(Clone, Copy, PartialEq)] +#[derive(Clone, Copy, PartialEq, Eq)] pub struct ExternRef(Option<ExternAddr>); -#[derive(Clone, Copy, PartialEq)] +#[derive(Clone, Copy, PartialEq, Eq)] pub struct FuncRef(Option<FuncAddr>); impl Debug for ExternRef { - fn fmt(&self, f: &mut alloc::fmt::Formatter<'_>) -> alloc::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self.0 { Some(addr) => write!(f, "extern({addr:?})"), None => write!(f, "extern(null)"), @@ -39,7 +39,7 @@ impl Debug for ExternRef { } impl Debug for FuncRef { - fn fmt(&self, f: &mut alloc::fmt::Formatter<'_>) -> alloc::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self.0 { Some(addr) => write!(f, "func({addr:?})"), None => write!(f, "func(null)"), @@ -114,7 +114,7 @@ impl WasmValue { Self::F64(i) => ConstInstruction::F64Const(*i), Self::V128(i) => ConstInstruction::V128Const(*i), Self::RefFunc(i) => ConstInstruction::RefFunc(i.addr()), - _ => unimplemented!("no const_instr for {:?}", self), + Self::RefExtern(_) => unimplemented!("no const_instr for RefExtern"), } } @@ -220,15 +220,15 @@ impl WasmValue { fn cold() {} impl Debug for WasmValue { - fn fmt(&self, f: &mut alloc::fmt::Formatter<'_>) -> alloc::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { - WasmValue::I32(i) => write!(f, "i32({i})"), - WasmValue::I64(i) => write!(f, "i64({i})"), - WasmValue::F32(i) => write!(f, "f32({i})"), - WasmValue::F64(i) => write!(f, "f64({i})"), - WasmValue::V128(i) => write!(f, "v128({i:?})"), - WasmValue::RefExtern(i) => write!(f, "ref({i:?})"), - WasmValue::RefFunc(i) => write!(f, "func({i:?})"), + Self::I32(i) => write!(f, "i32({i})"), + Self::I64(i) => write!(f, "i64({i})"), + Self::F32(i) => write!(f, "f32({i})"), + Self::F64(i) => write!(f, "f64({i})"), + Self::V128(i) => write!(f, "v128({i:?})"), + Self::RefExtern(i) => write!(f, "ref({i:?})"), + Self::RefFunc(i) => write!(f, "func({i:?})"), } } } @@ -278,7 +278,7 @@ impl ValType { #[doc(hidden)] #[inline] pub fn is_simd(&self) -> bool { - matches!(self, ValType::V128) + matches!(self, Self::V128) } } |
