use std::error;
use std::fmt;
use std::io;
use std::convert;
#[derive(Debug, PartialEq)]
pub enum DecoderError {
InvalidInput,
Interrupted,
InputUnderflow,
InvalidTag,
}
impl From<io::Error> for DecoderError {
fn from(_err: io::Error) -> Self {
Self::Interrupted
}
}
impl From<convert::Infallible> for DecoderError { fn from(_: convert::Infallible) -> Self {
unreachable!()
}
}
impl fmt::Display for DecoderError {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::InvalidInput => write!(fmt, "Invalid byte stream."),
Self::Interrupted => write!(fmt, "Read operation interrupted."),
Self::InputUnderflow => write!(fmt, "Not enough bytes."),
Self::InvalidTag => write!(fmt, "Found tag with invalid number."),
}
}
}
impl error::Error for DecoderError {}