use std::error;
use std::ffi;
use std::fmt;
use std::io;
use std::result;
pub type Result<T> = result::Result<T, Error>;
#[derive(Debug)]
pub enum Error {
NewContext(io::Error),
InitContext(io::Error),
AuthCallbackPaniced(Box<error::Error>),
NulInPath(ffi::NulError),
Io(io::Error),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Error::NewContext(ref err) => write!(f, "New context error: {}", err),
Error::InitContext(ref err) => write!(f, "Init context error: {}", err),
Error::Io(ref err) => write!(f, "IO error: {}", err),
Error::NulInPath(ref err) => write!(f, "NUL in path: {}", err),
Error::AuthCallbackPaniced(ref err) => write!(f, "Auth callback paniced last time: {}", err)
}
}
}
impl error::Error for Error {
fn description(&self) -> &str {
match *self {
Error::NewContext(ref err) => err.description(),
Error::InitContext(ref err) => err.description(),
Error::Io(ref err) => err.description(),
Error::NulInPath(ref err) => err.description(),
Error::AuthCallbackPaniced(ref _err) => "panic in auth callback",
}
}
fn cause(&self) -> Option<&error::Error> {
match *self {
Error::NewContext(ref err) => Some(err),
Error::InitContext(ref err) => Some(err),
Error::Io(ref err) => Some(err),
Error::NulInPath(ref err) => Some(err),
Error::AuthCallbackPaniced(ref err) => Some(err.as_ref()),
}
}
}
impl From<io::Error> for Error {
fn from(err: io::Error) -> Self {
Error::Io(err)
}
}
impl From<ffi::NulError> for Error {
fn from(err: ffi::NulError) -> Self {
Error::NulInPath(err)
}
}