use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Error<E> {
Read(E),
Corrupted {
alg_id: u64,
reason: String,
},
}
impl<E: fmt::Display> fmt::Display for Error<E> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Read(e) => write!(f, "read error: {e}"),
Self::Corrupted { alg_id, reason } => {
write!(f, "corrupted state for algorithm {alg_id}: {reason}")
},
}
}
}
impl<E: std::error::Error + 'static> std::error::Error for Error<E> {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Read(e) => Some(e),
Self::Corrupted { .. } => None,
}
}
}
pub type Result<T, E> = std::result::Result<T, Error<E>>;