Skip to main content

facet_cbor/
error.rs

1use core::fmt;
2
3/// Errors that can occur during CBOR serialization or deserialization.
4#[derive(Debug)]
5pub enum CborError {
6    ReflectError(String),
7    UnsupportedType(String),
8    UnexpectedEof,
9    InvalidCbor(String),
10    TypeMismatch { expected: String, got: String },
11}
12
13impl fmt::Display for CborError {
14    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
15        match self {
16            CborError::ReflectError(msg) => write!(f, "reflect error: {msg}"),
17            CborError::UnsupportedType(msg) => write!(f, "unsupported type: {msg}"),
18            CborError::UnexpectedEof => write!(f, "unexpected end of input"),
19            CborError::InvalidCbor(msg) => write!(f, "invalid CBOR: {msg}"),
20            CborError::TypeMismatch { expected, got } => {
21                write!(f, "type mismatch: expected {expected}, got {got}")
22            }
23        }
24    }
25}
26
27impl std::error::Error for CborError {}