cbor_nan_bstr/
error.rs

1/// Error types for cbor-nan-bstr
2#[derive(Debug, thiserror::Error)]
3pub enum Error {
4    #[error("CBOR error ({0})")]
5    Cbor(#[from] dcbor::Error),
6
7    #[error("invalid NaN length: expected 2, 4, 8, or 16 bytes, got {0} bytes")]
8    InvalidLength(usize),
9
10    #[error("not a NaN bit pattern")]
11    NotANan,
12}
13
14/// A specialized `Result` type for cbor-nan-bstr operations.
15pub type Result<T> = std::result::Result<T, Error>;
16
17impl From<Error> for String {
18    fn from(err: Error) -> Self { err.to_string() }
19}
20
21impl From<Error> for dcbor::Error {
22    fn from(err: Error) -> Self {
23        match err {
24            Error::Cbor(err) => err,
25            _ => dcbor::Error::msg(err),
26        }
27    }
28}