use std::error::Error;
use std::fmt;
pub type PathResult<T> = Result<T, PathError>;
pub struct PathError {
pub code: ErrorType,
pub description: String,
pub cause: Option<Box<Error>>,
}
impl fmt::Display for PathError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f,
"Code: {:?}, Description: {}",
self.code,
self.description)
}
}
impl fmt::Debug for PathError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(self, f)
}
}
impl Error for PathError {
fn description(&self) -> &str {
&self.description
}
}
#[derive(Debug, PartialEq, Eq)]
pub enum ErrorType {
PacketCounterOverflow,
Timeout,
Internal,
}
pub fn bail(code: ErrorType, description: &fmt::Display) -> PathError {
PathError {
code: code,
description: description.to_string(),
cause: None,
}
}
macro_rules! bail {($code:expr, $($fmt:tt)*) => (
return Err(::error::bail($code, &format_args!($($fmt)*)))
)}