pub type Result<T> = std::result::Result<T, Error>;
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Error {
Unimplemented(&'static str),
Eof,
Again,
InvalidData(String),
Unsupported(String),
}
impl Error {
pub fn invalid(msg: impl Into<String>) -> Self {
Error::InvalidData(msg.into())
}
pub fn unsupported(msg: impl Into<String>) -> Self {
Error::Unsupported(msg.into())
}
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Error::Unimplemented(what) => write!(f, "not yet implemented: {what}"),
Error::Eof => write!(f, "end of stream"),
Error::Again => write!(f, "more input required"),
Error::InvalidData(msg) => write!(f, "invalid data: {msg}"),
Error::Unsupported(msg) => write!(f, "unsupported: {msg}"),
}
}
}
impl std::error::Error for Error {}
impl From<crate::bits::OutOfData> for Error {
fn from(_: crate::bits::OutOfData) -> Self {
Error::InvalidData("bit reader ran out of data".into())
}
}