use std::fmt;
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 {
Self::InvalidData(msg.into())
}
pub fn unsupported(msg: impl Into<String>) -> Self {
Self::Unsupported(msg.into())
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Unimplemented(what) => write!(f, "not yet implemented: {what}"),
Self::Eof => write!(f, "end of stream"),
Self::Again => write!(f, "more input required"),
Self::InvalidData(msg) => write!(f, "invalid data: {msg}"),
Self::Unsupported(msg) => write!(f, "unsupported: {msg}"),
}
}
}
impl std::error::Error for Error {}