From 2d69fbb206ef620251f7cf6618131e6be226eca7 Mon Sep 17 00:00:00 2001 From: Henry Gressmann Date: Thu, 30 Nov 2023 15:58:37 +0100 Subject: chore: remove unneeded dependencies Signed-off-by: Henry Gressmann --- crates/tinywasm/Cargo.toml | 6 +++--- crates/tinywasm/src/error.rs | 23 ++++++++++++++++------- 2 files changed, 19 insertions(+), 10 deletions(-) (limited to 'crates') diff --git a/crates/tinywasm/Cargo.toml b/crates/tinywasm/Cargo.toml index 807a19f..02ea1f5 100644 --- a/crates/tinywasm/Cargo.toml +++ b/crates/tinywasm/Cargo.toml @@ -7,11 +7,11 @@ edition="2021" path="src/lib.rs" [dependencies] -thiserror={version="1.0", package="thiserror-core", default-features=false} +# fork of wasmparser with no_std support, see https://github.com/bytecodealliance/wasmtime/issues/3495 +# TODO: create dependency free parser wasmparser={version="0.100", package="wasmparser-nostd", default-features=false} tracing={version="0.1.38", default-features=false} # logging -hashbrown="0.14" [features] default=["std"] -std=["thiserror/std"] +std=[] diff --git a/crates/tinywasm/src/error.rs b/crates/tinywasm/src/error.rs index a253880..9b97a59 100644 --- a/crates/tinywasm/src/error.rs +++ b/crates/tinywasm/src/error.rs @@ -1,18 +1,27 @@ use alloc::string::{String, ToString}; -use thiserror::Error; +use core::fmt::Display; -#[derive(Debug, Error)] +#[derive(Debug)] pub enum Error { - #[error("error parsing module")] ParseError { message: String, offset: usize }, - - #[error("unsupported feature: {0}")] UnsupportedFeature(String), - - #[error("unknown error: {0}")] Other(String), } +impl Display for Error { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Self::ParseError { message, offset } => { + write!(f, "error parsing module: {} at offset {}", message, offset) + } + Self::UnsupportedFeature(feature) => write!(f, "unsupported feature: {}", feature), + Self::Other(message) => write!(f, "unknown error: {}", message), + } + } +} + +impl crate::std::error::Error for Error {} + impl Error { pub fn other(message: &str) -> Result { Err(Self::Other(message.to_string())) -- cgit v1.3.1