use self::Error::*;
use coin::Coin;
use either::Either;
use openssl::error as openssl;
use std::{error, fmt, io};
#[allow(missing_docs)]
#[derive(Debug)]
pub enum Error {
StaticMsg(&'static str),
Msg(String),
CoinNotSupported(Coin),
Io(io::Error),
OpenSsl(Either<openssl::Error, openssl::ErrorStack>),
}
impl error::Error for Error {
fn description(&self) -> &str {
match *self {
StaticMsg(s) => s,
Msg(ref s) => s,
CoinNotSupported(_) => "This coin is not supported",
Io(ref e) => e.description(),
OpenSsl(Either::Left(ref e)) => e.description(),
OpenSsl(Either::Right(ref e)) => e.description(),
}
}
fn cause(&self) -> Option<&error::Error> {
match *self {
StaticMsg(_) | Msg(_) | CoinNotSupported(_) => None,
Io(ref e) => Some(e),
OpenSsl(Either::Left(ref e)) => Some(e),
OpenSsl(Either::Right(ref e)) => Some(e),
}
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", error::Error::description(self))
}
}
impl From<String> for Error {
fn from(error: String) -> Self { Error::Msg(error) }
}
impl From<&'static str> for Error {
fn from(error: &'static str) -> Self { Error::StaticMsg(error) }
}
impl From<io::Error> for Error {
fn from(error: io::Error) -> Self { Error::Io(error) }
}
impl From<openssl::Error> for Error {
fn from(error: openssl::Error) -> Self { Error::OpenSsl(Either::Left(error)) }
}
impl From<openssl::ErrorStack> for Error {
fn from(error: openssl::ErrorStack) -> Self { Error::OpenSsl(Either::Right(error)) }
}