pub struct CborTagEncode<'a, T: 'a> { /* private fields */ }Expand description
A special type that can be used to encode CBOR tags.
This is a “special” type because its use is hard-coded into the implementation of the encoder. When encoded, the encoder will make sure that it is properly represented as a CBOR tag.
§Example
This example shows how to encode and decode a custom data type as a CBOR tag:
use cbor::CborTagEncode;
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
struct MyDataStructure {
data: Vec<u32>,
}
impl Encodable for MyDataStructure {
fn encode<E: Encoder>(&self, e: &mut E) -> Result<(), E::Error> {
// See a list of tags here:
// http://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml
//
// It is OK to choose your own tag number, but it's probably
// best to choose one that is unassigned in the IANA registry.
CborTagEncode::new(100_000, &self.data).encode(e)
}
}
// Note that the special type `CborTagEncode` isn't needed when decoding.
// You can decode into your `MyDataStructure` type directly:
impl Decodable for MyDataStructure {
fn decode<D: Decoder>(d: &mut D) -> Result<MyDataStructure, D::Error> {
// Read the tag number and throw it away. YOU MUST DO THIS!
try!(d.read_u64());
// The *next* data item is the actual data.
Ok(MyDataStructure { data: try!(Decodable::decode(d)) })
}
}Implementations§
Source§impl<'a, T> CborTagEncode<'a, T>
impl<'a, T> CborTagEncode<'a, T>
Sourcepub fn new(tag: u64, data: &'a T) -> CborTagEncode<'a, T>
pub fn new(tag: u64, data: &'a T) -> CborTagEncode<'a, T>
Create a new value that is encodable as a CBOR tag.
You can see a list of currently assigned tag numbers here: http://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml
Note that it is OK to choose your own tag number for your own application specific purpose, but it should probably be one that is currently unassigned in the IANA registry.
tag is the tag number and data is the actual data item to encode.
Trait Implementations§
Source§impl<'a, T: Clone + 'a> Clone for CborTagEncode<'a, T>
impl<'a, T: Clone + 'a> Clone for CborTagEncode<'a, T>
Source§fn clone(&self) -> CborTagEncode<'a, T>
fn clone(&self) -> CborTagEncode<'a, T>
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<'a, T: Debug + 'a> Debug for CborTagEncode<'a, T>
impl<'a, T: Debug + 'a> Debug for CborTagEncode<'a, T>
Source§impl<'a, T: Encodable + 'a> Encodable for CborTagEncode<'a, T>
impl<'a, T: Encodable + 'a> Encodable for CborTagEncode<'a, T>
Source§impl<'a, T: PartialEq + 'a> PartialEq for CborTagEncode<'a, T>
impl<'a, T: PartialEq + 'a> PartialEq for CborTagEncode<'a, T>
impl<'a, T: 'a> StructuralPartialEq for CborTagEncode<'a, T>
Auto Trait Implementations§
impl<'a, T> Freeze for CborTagEncode<'a, T>
impl<'a, T> RefUnwindSafe for CborTagEncode<'a, T>where
T: RefUnwindSafe,
impl<'a, T> Send for CborTagEncode<'a, T>where
T: Sync,
impl<'a, T> Sync for CborTagEncode<'a, T>where
T: Sync,
impl<'a, T> Unpin for CborTagEncode<'a, T>
impl<'a, T> UnwindSafe for CborTagEncode<'a, T>where
T: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit)