1#[derive(Debug, Default)]
2pub struct Trap {
3 _private: (),
4}
5
6impl core::fmt::Display for Trap {
7 fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result {
8 fmt.write_str("execution trapped")
10 }
11}
12
13#[cfg(feature = "std")]
14impl std::error::Error for Trap {}
15
16#[derive(Debug)]
17pub enum ExecutionError<T> {
18 Trap(Trap),
19 Error(T),
20 OutOfGas,
21}
22
23impl<T> From<T> for ExecutionError<T> {
24 fn from(error: T) -> Self {
25 ExecutionError::Error(error)
26 }
27}
28
29impl<T> core::fmt::Display for ExecutionError<T>
30where
31 T: core::fmt::Display,
32{
33 fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result {
34 match self {
35 ExecutionError::Trap(trap) => trap.fmt(fmt),
36 ExecutionError::Error(error) => error.fmt(fmt),
37 ExecutionError::OutOfGas => fmt.write_str("out of gas"),
38 }
39 }
40}
41
42#[cfg(feature = "std")]
43impl<T> std::error::Error for ExecutionError<T> where T: core::fmt::Debug + core::fmt::Display {}