Trait cbor_data::Writer[][src]

pub trait Writer: Sized {
    type Output;
    fn max_definite(&self) -> Option<u64>;

    fn write_pos(
        self,
        value: u64,
        tags: impl IntoIterator<Item = u64>
    ) -> Self::Output { ... }
fn write_neg(
        self,
        value: u64,
        tags: impl IntoIterator<Item = u64>
    ) -> Self::Output { ... }
fn write_bytes(
        self,
        value: &[u8],
        tags: impl IntoIterator<Item = u64>
    ) -> Self::Output { ... }
fn write_str(
        self,
        value: &str,
        tags: impl IntoIterator<Item = u64>
    ) -> Self::Output { ... }
fn write_bool(
        self,
        value: bool,
        tags: impl IntoIterator<Item = u64>
    ) -> Self::Output { ... }
fn write_null(self, tags: impl IntoIterator<Item = u64>) -> Self::Output { ... }
fn write_undefined(
        self,
        tags: impl IntoIterator<Item = u64>
    ) -> Self::Output { ... }
fn write_lit(
        self,
        value: Literal,
        tags: impl IntoIterator<Item = u64>
    ) -> Self::Output { ... }
fn write_array<F>(
        self,
        tags: impl IntoIterator<Item = u64>,
        f: F
    ) -> Self::Output
    where
        F: FnOnce(&mut ArrayWriter<'_>)
, { ... }
fn write_array_ret<T, F>(
        self,
        tags: impl IntoIterator<Item = u64>,
        f: F
    ) -> (Self::Output, T)
    where
        F: FnOnce(&mut ArrayWriter<'_>) -> T
, { ... }
fn write_dict<F>(
        self,
        tags: impl IntoIterator<Item = u64>,
        f: F
    ) -> Self::Output
    where
        F: FnOnce(&mut DictWriter<'_>)
, { ... }
fn write_dict_ret<T, F>(
        self,
        tags: impl IntoIterator<Item = u64>,
        f: F
    ) -> (Self::Output, T)
    where
        F: FnOnce(&mut DictWriter<'_>) -> T
, { ... }
fn write_canonical(self, bytes: &[u8]) -> Option<Self::Output> { ... }
fn write_trusting(self, bytes: &[u8]) -> Self::Output { ... } }

Low-level primitives for emitting CBOR items.

The methods of this trait give you full control over the encoding of values according to the CBOR specification (apart from the technically allowed non-optimal integer encodings). It allows you to emit any item tagged with any number you desire.

If you are looking for convenient methods of writing end-user data types please refer to the Encoder trait.

Associated Types

Loading content...

Required methods

fn max_definite(&self) -> Option<u64>[src]

Configured maximum array or dict length up to which definite size encoding is used.

Loading content...

Provided methods

fn write_pos(
    self,
    value: u64,
    tags: impl IntoIterator<Item = u64>
) -> Self::Output
[src]

Write a unsigned value of up to 64 bits. Tags are from outer to inner.

fn write_neg(
    self,
    value: u64,
    tags: impl IntoIterator<Item = u64>
) -> Self::Output
[src]

Write a negative value of up to 64 bits — the represented number is -1 - value. Tags are from outer to inner.

fn write_bytes(
    self,
    value: &[u8],
    tags: impl IntoIterator<Item = u64>
) -> Self::Output
[src]

Write the given slice as a definite size byte string. Tags are from outer to inner.

fn write_str(
    self,
    value: &str,
    tags: impl IntoIterator<Item = u64>
) -> Self::Output
[src]

Write the given slice as a definite size string. Tags are from outer to inner.

fn write_bool(
    self,
    value: bool,
    tags: impl IntoIterator<Item = u64>
) -> Self::Output
[src]

Tags are from outer to inner.

fn write_null(self, tags: impl IntoIterator<Item = u64>) -> Self::Output[src]

Tags are from outer to inner.

fn write_undefined(self, tags: impl IntoIterator<Item = u64>) -> Self::Output[src]

Tags are from outer to inner.

fn write_lit(
    self,
    value: Literal,
    tags: impl IntoIterator<Item = u64>
) -> Self::Output
[src]

Write custom literal value — RFC 7049 §2.3 is required reading. Tags are from outer to inner.

fn write_array<F>(
    self,
    tags: impl IntoIterator<Item = u64>,
    f: F
) -> Self::Output where
    F: FnOnce(&mut ArrayWriter<'_>), 
[src]

Write a nested array using the given closure that receives an array builder. Tags are from outer to inner.

let cbor = CborBuilder::default().write_array(None, |builder| {
    builder.write_array_ret(None, |builder| {
        builder.write_pos(42, None);
    });
});

fn write_array_ret<T, F>(
    self,
    tags: impl IntoIterator<Item = u64>,
    f: F
) -> (Self::Output, T) where
    F: FnOnce(&mut ArrayWriter<'_>) -> T, 
[src]

Write a nested array using the given closure that receives an array builder. Tags are from outer to inner.

let (cbor, ret) = CborBuilder::default().write_array_ret(None, |builder| {
    builder.write_array_ret(None, |builder| {
        builder.write_pos(42, None);
    });
    42
});
assert_eq!(ret, 42);

fn write_dict<F>(
    self,
    tags: impl IntoIterator<Item = u64>,
    f: F
) -> Self::Output where
    F: FnOnce(&mut DictWriter<'_>), 
[src]

Write a nested dict using the given closure that receives a dict builder. Tags are from outer to inner.

let cbor = CborBuilder::default().write_array(None, |builder | {
    builder.write_dict_ret(None, |builder| {
        builder.with_key("y", |b| b.write_pos(42, None));
    });
});

fn write_dict_ret<T, F>(
    self,
    tags: impl IntoIterator<Item = u64>,
    f: F
) -> (Self::Output, T) where
    F: FnOnce(&mut DictWriter<'_>) -> T, 
[src]

Write a nested dict using the given closure that receives a dict builder. Tags are from outer to inner.

let (cbor, ret) = CborBuilder::default().write_array_ret(None, |builder | {
    builder.write_dict_ret(None, |builder| {
        builder.with_key("y", |b| b.write_pos(42, None));
    });
    42
});
assert_eq!(ret, 42);

fn write_canonical(self, bytes: &[u8]) -> Option<Self::Output>[src]

Interpret the given bytes as a single CBOR item and write it to this builder, canonicalising its contents like CborOwned::canonical()

fn write_trusting(self, bytes: &[u8]) -> Self::Output[src]

Assume that the given bytes are a well-formed single CBOR item and write it to this builder.

If those bytes are not valid CBOR you get to keep the pieces!

Loading content...

Implementations on Foreign Types

impl<T> Writer for &mut T where
    T: Writer<Output = T>, 
[src]

type Output = Self

Loading content...

Implementors

impl<'a> Writer for ArrayWriter<'a>[src]

type Output = Self

impl<'a, 'b> Writer for SingleBuilder<'a, 'b>[src]

type Output = SingleResult

impl<'a, O: CborOutput> Writer for CborBuilder<'a, O>[src]

type Output = O::Output

Loading content...