rust/src/error.rs

36 lines
1 KiB
Rust
Raw Normal View History

2016-03-14 21:48:00 -06:00
use std::error::Error;
use std::fmt;
#[derive(Clone, Debug)]
pub enum EvalError {
DanglingPointerDeref,
InvalidBool,
PointerOutOfBounds,
InvalidPointerAccess,
ReadBytesAsPointer,
2016-03-14 21:48:00 -06:00
}
pub type EvalResult<T> = Result<T, EvalError>;
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",
2016-03-14 21:48:00 -06:00
}
}
fn cause(&self) -> Option<&Error> { None }
}
impl fmt::Display for EvalError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}