pub struct Writer { /* private fields */ }Expand description
An incremental writer to a Vec<u8>, with support for delayed labels.
Implementations§
source§impl Writer
impl Writer
sourcepub fn finish(self) -> Result<Vec<u8>>
pub fn finish(self) -> Result<Vec<u8>>
Finalizes all delayed labels and returns the resulting Vec<u8>.
Returns any error returned by the delays, which is usually if a label is not defined or is too large to fit in its slot.
sourcepub fn array<const N: usize>(&mut self, data: [u8; N])
pub fn array<const N: usize>(&mut self, data: [u8; N])
Writes some data.
This function is redundant, and exists only for symmetry.
sourcepub fn label(&mut self, label: Label)
pub fn label(&mut self, label: Label)
Places a label at the current position, so it can be referenced with delay.
sourcepub fn delay<const N: usize, F>(&mut self, cb: F)where
F: FnOnce(&DelayContext<'_>) -> Result<[u8; N], Box<dyn Error + Send + Sync>> + 'static,
pub fn delay<const N: usize, F>(&mut self, cb: F)where F: FnOnce(&DelayContext<'_>) -> Result<[u8; N], Box<dyn Error + Send + Sync>> + 'static,
Writes some bytes to be filled in later.
The given closure is called with a function that allows looking up labels. Other kinds of state are not currently officially allowed.
sourcepub fn reserve(&mut self, size: usize)
pub fn reserve(&mut self, size: usize)
Calls Vec::reserve on the underlying Vec.
source§impl Writer
impl Writer
Functions for writing primitives to the stream. The underlying functions are hidden from the docs for brevity.
Supported primitives are u8..=u128, i8..=i128, f32, f64.
The functions are suffixed with either _le or _be, for endianness. To use unsuffixed
versions, import either the Le or Be trait.