Skip to main content

faster_hex_thiserror/
error.rs

1#[derive(Clone, Copy, PartialEq, Eq)]
2#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
3pub enum Error {
4    InvalidChar,
5    InvalidLength(usize),
6    Overflow,
7}
8
9impl ::core::fmt::Debug for Error {
10    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
11        match *self {
12            Error::InvalidLength(len) => write!(f, "Invalid input length {len}"),
13            Error::InvalidChar => write!(f, "Invalid character"),
14            Error::Overflow => write!(f, "Overflow"),
15        }
16    }
17}
18
19impl ::core::fmt::Display for Error {
20    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
21        ::core::fmt::Debug::fmt(&self, f)
22    }
23}
24
25impl core::error::Error for Error {
26    fn description(&self) -> &str {
27        match *self {
28            Error::InvalidChar => "invalid character",
29            Error::InvalidLength(_) => "invalid length",
30            Error::Overflow => "overflow",
31        }
32    }
33}