#[derive(Debug)]
pub enum Error {
InvalidArgs(String),
InvalidData(String),
InvalidContext(String),
VerificationFailure(String),
IOError(std::io::Error),
ProtobufError(protobuf::Error),
}
impl std::error::Error for Error {}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::InvalidArgs(s) |
Self::InvalidData(s) |
Self::InvalidContext(s) |
Self::VerificationFailure(s) => write!(f, "{}", s),
Self::IOError(e) => write!(f, "I/O error: {}", e),
Self::ProtobufError(e) => write!(f, "Protobuf error: {}", e),
}
}
}
impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Self {
Self::IOError(e)
}
}
impl From<protobuf::Error> for Error {
fn from(e: protobuf::Error) -> Self {
Self::ProtobufError(e)
}
}
impl From<tempfile::PersistError> for Error {
fn from(e: tempfile::PersistError) -> Self {
Self::IOError(e.error)
}
}
impl From<tempfile::PathPersistError> for Error {
fn from(e: tempfile::PathPersistError) -> Self {
Self::IOError(std::io::Error::new(std::io::ErrorKind::Other, e))
}
}