use std::fmt;
#[derive(Debug)]
pub enum Error {
BinaryReader(wasmparser::BinaryReaderError),
Encoding(wasm_encoder::reencode::Error),
Other(String),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::BinaryReader(e) => write!(f, "{e}"),
Error::Encoding(e) => write!(f, "{e}"),
Error::Other(s) => write!(f, "{s}"),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::BinaryReader(e) => Some(e),
Error::Encoding(e) => Some(e),
Error::Other(_) => None,
}
}
}
impl From<wasmparser::BinaryReaderError> for Error {
fn from(e: wasmparser::BinaryReaderError) -> Self {
Error::BinaryReader(e)
}
}
impl From<wasm_encoder::reencode::Error> for Error {
fn from(e: wasm_encoder::reencode::Error) -> Self {
Error::Encoding(e)
}
}
pub type Result<T> = std::result::Result<T, Error>;