Struct cbor::CborTagEncode [−][src]
pub struct CborTagEncode<'a, T: 'a> { /* fields omitted */ }
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)) }) } }
Methods
impl<'a, T> CborTagEncode<'a, T>
[src]
impl<'a, T> CborTagEncode<'a, T>
pub fn new(tag: u64, data: &'a T) -> CborTagEncode<'a, T>
[src]
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
impl<'a, T: Clone + 'a> Clone for CborTagEncode<'a, T>
[src]
impl<'a, T: Clone + 'a> Clone for CborTagEncode<'a, T>
fn clone(&self) -> CborTagEncode<'a, T>
[src]
fn clone(&self) -> CborTagEncode<'a, T>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl<'a, T: Debug + 'a> Debug for CborTagEncode<'a, T>
[src]
impl<'a, T: Debug + 'a> Debug for CborTagEncode<'a, T>
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl<'a, T: PartialEq + 'a> PartialEq for CborTagEncode<'a, T>
[src]
impl<'a, T: PartialEq + 'a> PartialEq for CborTagEncode<'a, T>
fn eq(&self, other: &CborTagEncode<'a, T>) -> bool
[src]
fn eq(&self, other: &CborTagEncode<'a, T>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &CborTagEncode<'a, T>) -> bool
[src]
fn ne(&self, other: &CborTagEncode<'a, T>) -> bool
This method tests for !=
.
impl<'a, T: Encodable + 'a> Encodable for CborTagEncode<'a, T>
[src]
impl<'a, T: Encodable + 'a> Encodable for CborTagEncode<'a, T>
Auto Trait Implementations
impl<'a, T> Send for CborTagEncode<'a, T> where
T: Sync,
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> Sync for CborTagEncode<'a, T> where
T: Sync,