Skip to main content

rwasm/types/
error.rs

1use crate::{types::HostError, CompilationError, TrapCode};
2use alloc::boxed::Box;
3use core::fmt::Formatter;
4
5#[derive(Debug)]
6pub enum RwasmError {
7    CompilationError(CompilationError),
8    TrapCode(TrapCode),
9    HostInterruption(Box<dyn HostError>),
10}
11
12impl From<CompilationError> for RwasmError {
13    fn from(err: CompilationError) -> Self {
14        RwasmError::CompilationError(err)
15    }
16}
17impl From<TrapCode> for RwasmError {
18    fn from(err: TrapCode) -> Self {
19        RwasmError::TrapCode(err)
20    }
21}
22
23impl core::fmt::Display for RwasmError {
24    fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
25        match self {
26            RwasmError::CompilationError(err) => write!(f, "{}", err),
27            RwasmError::TrapCode(err) => write!(f, "{}", err),
28            RwasmError::HostInterruption(_) => write!(f, "host interruption"),
29        }
30    }
31}