stak_engine/
error.rs

1use core::{
2    error::Error,
3    fmt::{self, Display, Formatter},
4};
5use stak_dynamic::DynamicError;
6use stak_r7rs::SmallError;
7
8/// An engine error
9#[derive(Debug)]
10pub enum EngineError {
11    /// A dynamic primitive error.
12    Dynamic(DynamicError),
13    /// An R7RS-small error.
14    Small(SmallError),
15    /// A virtual machine error.
16    Vm(stak_vm::Error),
17}
18
19impl From<DynamicError> for EngineError {
20    fn from(error: DynamicError) -> Self {
21        Self::Dynamic(error)
22    }
23}
24
25impl From<SmallError> for EngineError {
26    fn from(error: SmallError) -> Self {
27        Self::Small(error)
28    }
29}
30
31impl From<stak_vm::Error> for EngineError {
32    fn from(error: stak_vm::Error) -> Self {
33        Self::Vm(error)
34    }
35}
36
37impl Error for EngineError {}
38
39impl Display for EngineError {
40    fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
41        match self {
42            Self::Dynamic(error) => write!(formatter, "{error}"),
43            Self::Small(error) => write!(formatter, "{error}"),
44            Self::Vm(error) => write!(formatter, "{error}"),
45        }
46    }
47}