base16ct/
error.rs

1use core::fmt;
2
3/// Result type with the `base16ct` crate's [`Error`] type.
4pub type Result<T> = core::result::Result<T, Error>;
5
6/// Error type
7#[derive(Clone, Eq, PartialEq, Debug)]
8pub enum Error {
9    /// Invalid encoding of provided Base16 string.
10    InvalidEncoding,
11
12    /// Insufficient output buffer length.
13    InvalidLength,
14}
15
16impl fmt::Display for Error {
17    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18        match self {
19            Error::InvalidEncoding => f.write_str("invalid Base16 encoding"),
20            Error::InvalidLength => f.write_str("invalid Base16 length"),
21        }
22    }
23}
24
25#[cfg(feature = "std")]
26impl std::error::Error for Error {}
27
28impl From<Error> for core::fmt::Error {
29    fn from(_: Error) -> core::fmt::Error {
30        core::fmt::Error::default()
31    }
32}