stak_engine/
error.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use core::{
    error::Error,
    fmt::{self, Display, Formatter},
};
use stak_dynamic::DynamicError;
use stak_r7rs::SmallError;

/// An engine error
#[derive(Debug)]
pub enum EngineError {
    /// A dynamic primitive error.
    Dynamic(DynamicError),
    /// An R7RS-small error.
    Small(SmallError),
    /// A virtual machine error.
    Vm(stak_vm::Error),
}

impl From<DynamicError> for EngineError {
    fn from(error: DynamicError) -> Self {
        Self::Dynamic(error)
    }
}

impl From<SmallError> for EngineError {
    fn from(error: SmallError) -> Self {
        Self::Small(error)
    }
}

impl From<stak_vm::Error> for EngineError {
    fn from(error: stak_vm::Error) -> Self {
        Self::Vm(error)
    }
}

impl Error for EngineError {}

impl Display for EngineError {
    fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
        match self {
            Self::Dynamic(error) => write!(formatter, "{error}"),
            Self::Small(error) => write!(formatter, "{error}"),
            Self::Vm(error) => write!(formatter, "{error}"),
        }
    }
}