use core::convert::Infallible;
use std::{fmt, io};
#[derive(Debug)]
#[non_exhaustive]
pub enum Error {
Io(io::Error),
Decode(minicbor::decode::Error),
Encode(minicbor::encode::Error<Infallible>),
InvalidLen
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::Io(e) => write!(f, "i/o error: {e}"),
Error::Decode(e) => write!(f, "decode error: {e}"),
Error::Encode(e) => write!(f, "encode error: {e}"),
Error::InvalidLen => f.write_str("invalid length")
}
}
}
impl core::error::Error for Error {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
match self {
Error::Io(e) => Some(e),
Error::Decode(e) => Some(e),
Error::Encode(e) => Some(e),
Error::InvalidLen => None
}
}
}
impl From<io::Error> for Error {
fn from(e: io::Error) -> Self {
Error::Io(e)
}
}
impl From<minicbor::encode::Error<Infallible>> for Error {
fn from(e: minicbor::encode::Error<Infallible>) -> Self {
Error::Encode(e)
}
}