#![feature(box_syntax, box_patterns)]
use std::{error, fmt, result};
#[macro_export]
macro_rules! err_at {
($v:ident, msg: $($arg:expr),+) => {{
let prefix = format!("{}:{}", file!(), line!());
Err(Error::$v(prefix, format!($($arg),+)))
}};
($v:ident, $e:expr) => {{
match $e {
Ok(val) => Ok(val),
Err(err) => {
let prefix = format!("{}:{}", file!(), line!());
Err(Error::$v(prefix, format!("{}", err)))
}
}
}};
($v:ident, $e:expr, $($arg:expr),+) => {{
match $e {
Ok(val) => Ok(val),
Err(err) => {
let prefix = format!("{}:{}", file!(), line!());
let msg = format!($($arg),+);
Err(Error::$v(prefix, format!("{} {}", err, msg)))
}
}
}};
}
#[macro_use]
extern crate data_encoding_macro;
pub mod multiaddr;
pub mod multibase;
pub mod multicodec;
pub mod multihash;
pub type Result<T> = result::Result<T, Error>;
pub enum Error {
Fatal(String, String),
IOError(String, String),
Invalid(String, String),
DecodeError(String, String),
BadInput(String, String),
BadAddr(String, String),
NotImplemented(String, String),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> {
use Error::*;
match self {
Fatal(p, msg) => write!(f, "{} Fatal: {}", p, msg),
IOError(p, msg) => write!(f, "{} IOError: {}", p, msg),
Invalid(p, msg) => write!(f, "{} Invalid: {}", p, msg),
DecodeError(p, msg) => write!(f, "{} DecodeError: {}", p, msg),
BadInput(p, msg) => write!(f, "{} BadInput: {}", p, msg),
BadAddr(p, msg) => write!(f, "{} BadAddr: {}", p, msg),
NotImplemented(p, msg) => write!(f, "{} NotImplemented: {}", p, msg),
}
}
}
impl fmt::Debug for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> {
write!(f, "{}", self)
}
}
impl error::Error for Error {}