use protobuf;
use std::convert::From;
use std::{self, fmt, io};
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug)]
pub enum Error {
Io(io::Error),
Pbf(protobuf::ProtobufError),
UnsupportedData,
InvalidData,
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Error::Io(ref e) => write!(f, "Io({})", e),
Error::Pbf(ref e) => write!(f, "Pbf({})", e),
Error::UnsupportedData => write!(f, "UnsupportedData"),
Error::InvalidData => write!(f, "InvalidData"),
}
}
}
impl std::error::Error for Error {
fn cause(&self) -> Option<&dyn std::error::Error> {
match *self {
Error::Io(ref e) => Some(e),
Error::Pbf(ref e) => Some(e),
Error::UnsupportedData | Error::InvalidData => None,
}
}
}
impl From<io::Error> for Error {
fn from(err: io::Error) -> Error {
Error::Io(err)
}
}
impl From<protobuf::ProtobufError> for Error {
fn from(err: protobuf::ProtobufError) -> Error {
Error::Pbf(err)
}
}