dcbor/
cbor_codable.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import_stdlib!();

use crate::CBOR;

pub trait CBOREncodable: Into<CBOR> + Clone {
    fn to_cbor(&self) -> CBOR {
        self.clone().into()
    }

    fn to_cbor_data(&self) -> Vec<u8> {
        self.to_cbor().to_cbor_data()
    }
}

impl<T> CBOREncodable for T where T: Into<CBOR> + Clone { }

pub trait CBORDecodable: TryFrom<CBOR> { }

impl<T> CBORDecodable for T where T: TryFrom<CBOR> { }

/// A type that can be encoded to or decoded from CBOR.
pub trait CBORCodable { }

impl<T> CBORCodable for T where T: CBORDecodable + CBOREncodable { }