[][src]Struct cbor_data::DictWriter

pub struct DictWriter<'a>(_);

Builder for a dict value, used by write_dict_rec().

see trait Encoder for usage examples

Implementations

impl<'a> DictWriter<'a>[src]

pub fn write_pos(&mut self, key: &str, value: u64, tag: Option<u64>)[src]

Write a unsigned value of up to 64 bits.

pub fn write_neg(&mut self, key: &str, value: u64, tag: Option<u64>)[src]

Write a negative value of up to 64 bits — the represented number is -1 - value.

pub fn write_bytes(&mut self, key: &str, value: &[u8], tag: Option<u64>)[src]

Write the given slice as a definite size byte string.

pub fn write_str(&mut self, key: &str, value: &str, tag: Option<u64>)[src]

Write the given slice as a definite size string.

pub fn write_bool(&mut self, key: &str, value: bool, tag: Option<u64>)[src]

pub fn write_null(&mut self, key: &str, tag: Option<u64>)[src]

pub fn write_undefined(&mut self, key: &str, tag: Option<u64>)[src]

pub fn write_lit(&mut self, key: &str, value: Literal, tag: Option<u64>)[src]

Write custom literal value — RFC 7049 §2.3 is required reading.

pub fn write_array(self, key: &str, tag: Option<u64>) -> ArrayBuilder<'a, Self>[src]

Write a nested array that is then filled by the returned builder. You can resume building this outer dict by using the finish() method.

pub fn write_array_rec<T, F>(&mut self, key: &str, tag: Option<u64>, f: F) -> T where
    F: FnMut(ArrayWriter<'_>) -> T, 
[src]

Write a nested array using the given closure that receives an array builder.

This method is very useful for recursively building a CBOR structure without statically known recursion limit, avoiding infinite type errors.

let (cbor, _) = CborBuilder::default().write_dict_rec(None, |mut builder| {
    builder.write_array_rec("x", None, |mut builder| {
        builder.write_pos(42, None);
    });
});

pub fn write_dict(self, key: &str, tag: Option<u64>) -> DictBuilder<'a, Self>[src]

Write a nested dict that is then filled by the returned builder. You can resume building this outer dict by using the finish() method.

pub fn write_dict_rec<T, F>(&mut self, key: &str, tag: Option<u64>, f: F) -> T where
    F: FnMut(DictWriter<'_>) -> T, 
[src]

Write a nested dict using the given closure that receives an dict builder.

This method is very useful for recursively building a CBOR structure without statically known recursion limit, avoiding infinite type errors.

let (cbor, _) = CborBuilder::default().write_dict_rec(None, |mut builder | {
    builder.write_dict_rec("x", None, |mut builder| {
        builder.write_pos("y", 42, None);
    });
});

pub fn with_key(self, key: &'a str) -> DictValueWriter<'a>[src]

Use Encoder methods for writing an entry into the dictionary.

use cbor_data::{CborBuilder, Encoder};

let cbor = CborBuilder::default().encode_dict(|mut builder| {
    builder
        .with_key("x")
        .encode_u64(25);
});

Trait Implementations

impl<'a> From<&'a mut Vec<u8, Global>> for DictWriter<'a>[src]

Auto Trait Implementations

impl<'a> RefUnwindSafe for DictWriter<'a>[src]

impl<'a> Send for DictWriter<'a>[src]

impl<'a> Sync for DictWriter<'a>[src]

impl<'a> Unpin for DictWriter<'a>[src]

impl<'a> !UnwindSafe for DictWriter<'a>[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.