Struct cbor_data::CborBuilder
source · pub struct CborBuilder<'a, O: CborOutput> { /* private fields */ }Expand description
Builder for a single CBOR value.
Implementations§
source§impl<'a> CborBuilder<'a, WithOutput>
impl<'a> CborBuilder<'a, WithOutput>
sourcepub fn with_scratch_space(v: &'a mut Vec<u8>) -> Self
pub fn with_scratch_space(v: &'a mut Vec<u8>) -> Self
Create a builder that clears the given vector and writes into it.
You can use this to reuse a scratch space across multiple values being built, e.g. by keeping the same vector in a thread-local variable.
source§impl<'a> CborBuilder<'a, NoOutput>
impl<'a> CborBuilder<'a, NoOutput>
source§impl<'a, O: CborOutput> CborBuilder<'a, O>
impl<'a, O: CborOutput> CborBuilder<'a, O>
sourcepub fn with_max_definite_size(self, max_definite: Option<u64>) -> Self
pub fn with_max_definite_size(self, max_definite: Option<u64>) -> Self
Configure the limit above which indefinite size encoding will be used.
The default is 255, which is the largest size up to which definite size is at least as
compact as indefinite size. Set to 23 to avoid moving bytes around when finishing the array.
Set to None to always use indefinite size encoding.
Trait Implementations§
source§impl Default for CborBuilder<'static, WithOutput>
impl Default for CborBuilder<'static, WithOutput>
source§impl<'a, O: CborOutput> Writer for CborBuilder<'a, O>
impl<'a, O: CborOutput> Writer for CborBuilder<'a, O>
type Output = <O as CborOutput>::Output
source§fn max_definite(&self) -> Option<u64>
fn max_definite(&self) -> Option<u64>
Configured maximum array or dict length up to which definite size encoding is used.
source§fn write_pos(
self,
value: u64,
tags: impl IntoIterator<Item = u64>,
) -> Self::Output
fn write_pos( self, value: u64, tags: impl IntoIterator<Item = u64>, ) -> Self::Output
Write a unsigned value of up to 64 bits.
Tags are from outer to inner.
source§fn write_neg(
self,
value: u64,
tags: impl IntoIterator<Item = u64>,
) -> Self::Output
fn write_neg( self, value: u64, tags: impl IntoIterator<Item = u64>, ) -> Self::Output
Write a negative value of up to 64 bits — the represented number is
-1 - value.
Tags are from outer to inner.source§fn write_bytes(
self,
value: &[u8],
tags: impl IntoIterator<Item = u64>,
) -> Self::Output
fn write_bytes( self, value: &[u8], tags: impl IntoIterator<Item = u64>, ) -> Self::Output
Write the given slice as a definite size byte string.
Tags are from outer to inner.
source§fn write_str(
self,
value: &str,
tags: impl IntoIterator<Item = u64>,
) -> Self::Output
fn write_str( self, value: &str, tags: impl IntoIterator<Item = u64>, ) -> Self::Output
Write the given slice as a definite size string.
Tags are from outer to inner.
source§fn write_bool(
self,
value: bool,
tags: impl IntoIterator<Item = u64>,
) -> Self::Output
fn write_bool( self, value: bool, tags: impl IntoIterator<Item = u64>, ) -> Self::Output
Tags are from outer to inner.
source§fn write_null(self, tags: impl IntoIterator<Item = u64>) -> Self::Output
fn write_null(self, tags: impl IntoIterator<Item = u64>) -> Self::Output
Tags are from outer to inner.
source§fn write_undefined(self, tags: impl IntoIterator<Item = u64>) -> Self::Output
fn write_undefined(self, tags: impl IntoIterator<Item = u64>) -> Self::Output
Tags are from outer to inner.
source§fn write_lit(
self,
value: Literal,
tags: impl IntoIterator<Item = u64>,
) -> Self::Output
fn write_lit( self, value: Literal, tags: impl IntoIterator<Item = u64>, ) -> Self::Output
Write custom literal value — RFC 8949 §3.3 is required reading.
Tags are from outer to inner.
source§fn write_array<F>(
self,
tags: impl IntoIterator<Item = u64>,
f: F,
) -> Self::Outputwhere
F: FnOnce(&mut ArrayWriter<'_>),
fn write_array<F>(
self,
tags: impl IntoIterator<Item = u64>,
f: F,
) -> Self::Outputwhere
F: FnOnce(&mut ArrayWriter<'_>),
Write a nested array using the given closure that receives an array builder.
Tags are from outer to inner. Read more
source§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_array_ret<T, F>(
self,
tags: impl IntoIterator<Item = u64>,
f: F,
) -> (Self::Output, T)where
F: FnOnce(&mut ArrayWriter<'_>) -> T,
Write a nested array using the given closure that receives an array builder.
Tags are from outer to inner. Read more
source§fn write_dict<F>(
self,
tags: impl IntoIterator<Item = u64>,
f: F,
) -> Self::Outputwhere
F: FnOnce(&mut DictWriter<'_>),
fn write_dict<F>(
self,
tags: impl IntoIterator<Item = u64>,
f: F,
) -> Self::Outputwhere
F: FnOnce(&mut DictWriter<'_>),
Write a nested dict using the given closure that receives a dict builder.
Tags are from outer to inner. Read more
source§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_dict_ret<T, F>(
self,
tags: impl IntoIterator<Item = u64>,
f: F,
) -> (Self::Output, T)where
F: FnOnce(&mut DictWriter<'_>) -> T,
Write a nested dict using the given closure that receives a dict builder.
Tags are from outer to inner. Read more
source§fn write_canonical(self, bytes: &[u8]) -> Option<Self::Output>
fn write_canonical(self, bytes: &[u8]) -> Option<Self::Output>
Interpret the given bytes as a single CBOR item and write it to this builder,
canonicalising its contents like
CborOwned::canonical()source§fn write_trusting(self, bytes: &[u8]) -> Self::Output
fn write_trusting(self, bytes: &[u8]) -> Self::Output
Assume that the given bytes are a well-formed single CBOR item and write it to this builder. Read more
source§fn write_item(self, item: &Cbor) -> Self::Output
fn write_item(self, item: &Cbor) -> Self::Output
Write the given CBOR item
Auto Trait Implementations§
impl<'a, O> Freeze for CborBuilder<'a, O>
impl<'a, O> RefUnwindSafe for CborBuilder<'a, O>where
O: RefUnwindSafe,
impl<'a, O> Send for CborBuilder<'a, O>where
O: Send,
impl<'a, O> Sync for CborBuilder<'a, O>where
O: Sync,
impl<'a, O> Unpin for CborBuilder<'a, O>where
O: Unpin,
impl<'a, O> !UnwindSafe for CborBuilder<'a, O>
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> Encoder for Twhere
T: Writer,
impl<T> Encoder for Twhere
T: Writer,
fn encode_bool(self, value: bool) -> Self::Output
source§fn encode_u64(self, value: u64) -> Self::Output
fn encode_u64(self, value: u64) -> Self::Output
Encode an unsigned integer of at most 64 bit. Read more
source§fn encode_i64(self, value: i64) -> Self::Output
fn encode_i64(self, value: i64) -> Self::Output
Encode a signed integer of at most 64 bit. Read more
source§fn encode_f64(self, value: f64) -> Self::Output
fn encode_f64(self, value: f64) -> Self::Output
Encode a floating-point number of at most 64 bit. Read more
source§fn encode_array<F>(self, f: F) -> Self::Outputwhere
F: FnMut(&mut ArrayWriter<'_>),
fn encode_array<F>(self, f: F) -> Self::Outputwhere
F: FnMut(&mut ArrayWriter<'_>),
Write an array that is then filled by the provided closure using the passed builder. Read more
source§fn encode_dict<F>(self, f: F) -> Self::Outputwhere
F: FnMut(&mut DictWriter<'_>),
fn encode_dict<F>(self, f: F) -> Self::Outputwhere
F: FnMut(&mut DictWriter<'_>),
Write a dict that is then filled by the provided closure using the passed builder. Read more