use std::{error, fmt::Display};
#[non_exhaustive]
#[derive(Debug)]
pub enum Error {
Zero,
InvalidTag(u32),
InvalidAscii(String),
DataTooLarge(usize),
InvalidChar(u32),
Io(std::io::Error),
Utf8(std::str::Utf8Error),
Other(&'static str),
}
use Error::*;
impl Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f, "{:?}", self)
}
}
impl error::Error for Error {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match self {
Io(e) => Some(e),
Utf8(e) => Some(e),
_ => None,
}
}
}
impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Self {
Io(e)
}
}
impl From<&'static str> for Error {
fn from(s: &'static str) -> Self {
Other(s)
}
}