[][src]Struct cbor_data::DictBuilder

pub struct DictBuilder<'a, T>(_, _);

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

Calling the finish() method will return either the fully constructed CBOR value (if this was the top-level dict) or the builder of the array or dict into which this dict was placed.

If you want to recursively create a CBOR structure without statically known recursion limit then you’ll want to take a look at the WriteToDict::write_dict_rec() method (the compiler would otherwise kindly inform you of a type expansion hitting the recursion limit while instantiating your recursive function).

see trait Encoder for usage examples

Implementations

impl<'a, T: 'a> DictBuilder<'a, T>[src]

pub fn finish(self) -> T[src]

Finish building this dict and return to the outer context. In case of a top-level dict this returns the complete Cbor value.

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<F, U>(&mut self, key: &str, tag: Option<u64>, f: F) -> U where
    F: FnMut(ArrayWriter<'_>) -> U, 
[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 mut cbor = CborBuilder::default().write_dict(None);
cbor.write_array_rec("x", None, |mut builder| {
    builder.write_pos(42, None);
});
let cbor = cbor.finish();

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<F, U>(&mut self, key: &str, tag: Option<u64>, f: F) -> U where
    F: FnMut(DictWriter<'_>) -> U, 
[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 mut cbor = CborBuilder::default().write_dict(None);
cbor.write_dict_rec("x", None, |mut builder| {
    builder.write_pos("y", 42, None);
});
let cbor = cbor.finish();

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

Use Encoder methods for writing an entry into the dictionary.

use cbor_data::{CborBuilder, Encoder};

let cbor = CborBuilder::default()
    .write_dict(None)
    .with_key("x")
    .encode_u64(25)
    .finish();

Auto Trait Implementations

impl<'a, T> !RefUnwindSafe for DictBuilder<'a, T>[src]

impl<'a, T> !Send for DictBuilder<'a, T>[src]

impl<'a, T> !Sync for DictBuilder<'a, T>[src]

impl<'a, T> Unpin for DictBuilder<'a, T>[src]

impl<'a, T> !UnwindSafe for DictBuilder<'a, T>[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.