From f9f760f487cfb08aa7992439bf748f7dcd46466b Mon Sep 17 00:00:00 2001 From: Henry Gressmann Date: Tue, 6 May 2025 21:36:25 +0200 Subject: chore: cleanup Signed-off-by: Henry Gressmann --- crates/types/src/archive.rs | 10 +++++----- crates/types/src/instructions.rs | 2 +- crates/types/src/lib.rs | 26 +++++++++++++------------- crates/types/src/value.rs | 28 ++++++++++++++-------------- 4 files changed, 33 insertions(+), 33 deletions(-) (limited to 'crates/types/src') 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 { + pub fn from_twasm(wasm: &[u8]) -> Result { 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 -#[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 -#[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> From 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> From for ValueCounts { impl<'a, T: IntoIterator> From 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, @@ -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); -#[derive(Clone, Copy, PartialEq)] +#[derive(Clone, Copy, PartialEq, Eq)] pub struct FuncRef(Option); 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) } } -- cgit v1.3.1