1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use crate::{CBOR, error::Error};

/// A type that can be decoded from CBOR.
pub trait CBORDecodable: 'static {
    /// Creates an instance of this type from CBOR symbolic representation.
    fn from_cbor(cbor: &CBOR) -> Result<Self, Error> where Self: Sized;

    /// Creates an instance of this type from encoded CBOR binary data.
    fn from_cbor_data(cbor_data: &[u8]) -> Result<Self, Error> where Self: Sized {
        Self::from_cbor(&CBOR::from_data(cbor_data)?)
    }
}

impl CBORDecodable for CBOR {
    fn from_cbor(cbor: &CBOR) -> Result<Self, Error> {
        Ok(cbor.clone())
    }
}