diff options
| author | Henry <mail@henrygressmann.de> | 2026-04-03 17:55:37 +0200 |
|---|---|---|
| committer | Henry <mail@henrygressmann.de> | 2026-04-03 17:55:37 +0200 |
| commit | 51bac3ce0e72195fa3ebf3ef4fb287bc5451b6f7 (patch) | |
| tree | 139d4f609ab44d531cab20e96774f85c351123d8 /crates/types/src | |
| parent | 065dc608ab25030d1719fef4dd55271c95245884 (diff) | |
chore: fix debug feature
Signed-off-by: Henry <mail@henrygressmann.de>
Diffstat (limited to 'crates/types/src')
| -rw-r--r-- | crates/types/src/archive.rs | 12 | ||||
| -rw-r--r-- | crates/types/src/instructions.rs | 2 | ||||
| -rw-r--r-- | crates/types/src/lib.rs | 22 | ||||
| -rw-r--r-- | crates/types/src/value.rs | 36 |
4 files changed, 36 insertions, 36 deletions
diff --git a/crates/types/src/archive.rs b/crates/types/src/archive.rs index 069addf..dc98e30 100644 --- a/crates/types/src/archive.rs +++ b/crates/types/src/archive.rs @@ -4,10 +4,10 @@ use alloc::vec::Vec; use crate::TinyWasmModule; -const TWASM_MAGIC_PREFIX: &[u8; 4] = b"TWAS"; -const TWASM_VERSION: &[u8; 2] = b"03"; #[rustfmt::skip] const TWASM_MAGIC: [u8; 16] = [ TWASM_MAGIC_PREFIX[0], TWASM_MAGIC_PREFIX[1], TWASM_MAGIC_PREFIX[2], TWASM_MAGIC_PREFIX[3], TWASM_VERSION[0], TWASM_VERSION[1], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; +const TWASM_MAGIC_PREFIX: &[u8; 4] = b"TWAS"; +const TWASM_VERSION: &[u8; 2] = b"03"; fn validate_magic(wasm: &[u8]) -> Result<usize, TwasmError> { if wasm.len() < TWASM_MAGIC.len() || &wasm[..TWASM_MAGIC_PREFIX.len()] != TWASM_MAGIC_PREFIX { @@ -66,14 +66,6 @@ mod tests { use super::*; #[test] - fn test_serialize() { - let wasm = TinyWasmModule::default(); - let twasm = wasm.serialize_twasm().expect("should serialize"); - let wasm2 = TinyWasmModule::from_twasm(&twasm).unwrap(); - assert_eq!(wasm, wasm2); - } - - #[test] fn test_invalid_magic() { let wasm = TinyWasmModule::default(); let mut twasm = wasm.serialize_twasm().expect("should serialize"); diff --git a/crates/types/src/instructions.rs b/crates/types/src/instructions.rs index 1165c06..83d0da8 100644 --- a/crates/types/src/instructions.rs +++ b/crates/types/src/instructions.rs @@ -48,10 +48,10 @@ pub enum ConstInstruction { /// Wasm Bytecode can map to multiple of these instructions. /// /// See <https://webassembly.github.io/spec/core/binary/instructions.html> +#[rustfmt::skip] #[derive(Clone, Copy, PartialEq)] #[cfg_attr(feature = "debug", derive(Debug))] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] -#[rustfmt::skip] pub enum Instruction { LocalCopy32(LocalAddr, LocalAddr), LocalCopy64(LocalAddr, LocalAddr), LocalCopy128(LocalAddr, LocalAddr), LocalCopyRef(LocalAddr, LocalAddr), I32AddLocals(LocalAddr, LocalAddr), I64AddLocals(LocalAddr, LocalAddr), diff --git a/crates/types/src/lib.rs b/crates/types/src/lib.rs index 78b83d0..8a815cb 100644 --- a/crates/types/src/lib.rs +++ b/crates/types/src/lib.rs @@ -2,9 +2,9 @@ no_crate_inject, attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_assignments, unused_variables)) ))] -#![warn(missing_debug_implementations, rust_2018_idioms, unreachable_pub)] +#![warn(rust_2018_idioms, unreachable_pub)] #![no_std] -#![forbid(unsafe_code)] +#![deny(unsafe_code)] //! Types used by [`tinywasm`](https://docs.rs/tinywasm) and [`tinywasm_parser`](https://docs.rs/tinywasm_parser). @@ -50,7 +50,7 @@ pub mod archive; #[cfg(not(feature = "archive"))] pub mod archive { - #[derive(Debug)] + #[cfg_attr(feature = "debug", derive(Debug))] pub enum TwasmError {} impl core::fmt::Display for TwasmError { fn fmt(&self, _: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { @@ -272,6 +272,12 @@ pub struct WasmFunction { // wrapper around Arc<[T]> to support serde serialization and deserialization pub struct ArcSlice<T>(pub Arc<[T]>); +impl<T: Debug> Debug for ArcSlice<T> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + self.0.as_ref().fmt(f) + } +} + impl<T> From<alloc::vec::Vec<T>> for ArcSlice<T> { fn from(vec: alloc::vec::Vec<T>) -> Self { Self(Arc::from(vec)) @@ -292,21 +298,15 @@ impl<T> Deref for ArcSlice<T> { } } -impl<T: Debug> Debug for ArcSlice<T> { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - self.0.as_ref().fmt(f) - } -} - #[cfg(feature = "archive")] -impl<T: serde::Serialize + Debug> serde::Serialize for ArcSlice<T> { +impl<T: serde::Serialize> serde::Serialize for ArcSlice<T> { fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> { self.0.as_ref().serialize(serializer) } } #[cfg(feature = "archive")] -impl<'de, T: serde::Deserialize<'de> + Debug> serde::Deserialize<'de> for ArcSlice<T> { +impl<'de, T: serde::Deserialize<'de>> serde::Deserialize<'de> for ArcSlice<T> { fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> { let vec: alloc::vec::Vec<T> = alloc::vec::Vec::deserialize(deserializer)?; Ok(Self(Arc::from(vec))) diff --git a/crates/types/src/value.rs b/crates/types/src/value.rs index afaa0d3..8cc7f1b 100644 --- a/crates/types/src/value.rs +++ b/crates/types/src/value.rs @@ -23,12 +23,33 @@ pub enum WasmValue { RefFunc(FuncRef), } +impl Debug for WasmValue { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + 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:?})"), + #[cfg(feature = "debug")] + Self::RefExtern(i) => write!(f, "ref({i:?})"), + #[cfg(feature = "debug")] + Self::RefFunc(i) => write!(f, "func({i:?})"), + #[cfg(not(feature = "debug"))] + Self::RefExtern(_) => write!(f, "ref()"), + #[cfg(not(feature = "debug"))] + Self::RefFunc(_) => write!(f, "func()"), + } + } +} + #[derive(Clone, Copy, PartialEq, Eq)] pub struct ExternRef(Option<ExternAddr>); #[derive(Clone, Copy, PartialEq, Eq)] pub struct FuncRef(Option<FuncAddr>); +#[cfg(feature = "debug")] impl Debug for ExternRef { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self.0 { @@ -38,6 +59,7 @@ impl Debug for ExternRef { } } +#[cfg(feature = "debug")] impl Debug for FuncRef { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self.0 { @@ -268,20 +290,6 @@ impl WasmValue { } } -impl Debug for WasmValue { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - match self { - 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:?})"), - } - } -} - impl WasmValue { /// Get the type of a [`WasmValue`] #[inline] |
