use std::error::Error; use std::fmt; #[derive(Clone, Debug)] pub enum EvalError { DanglingPointerDeref, InvalidBool, PointerOutOfBounds, InvalidPointerAccess, ReadBytesAsPointer, } pub type EvalResult = Result; impl Error for EvalError { fn description(&self) -> &str { match *self { EvalError::DanglingPointerDeref => "dangling pointer was dereferenced", EvalError::InvalidBool => "invalid boolean value read", EvalError::PointerOutOfBounds => "pointer offset outside bounds of allocation", EvalError::InvalidPointerAccess => "a raw memory access tried to access part of a pointer value as bytes", EvalError::ReadBytesAsPointer => "attempted to read some raw bytes as a pointer address", } } fn cause(&self) -> Option<&Error> { None } } impl fmt::Display for EvalError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.description()) } }