pub struct SymbolBuffer<'a> { /* private fields */ }Expand description
A helper to write symbols into a buffer, tracking how many symbols were written.
Implementations§
Source§impl<'a> SymbolBuffer<'a>
impl<'a> SymbolBuffer<'a>
Sourcepub unsafe fn from_raw_parts(
symbols: *mut rmt_symbol_word_t,
written: usize,
free: usize,
) -> Self
pub unsafe fn from_raw_parts( symbols: *mut rmt_symbol_word_t, written: usize, free: usize, ) -> Self
Constructs a SymbolBuffer from its raw parts.
§Safety
You must ensure that the provided pointer is valid for both reads and writes, not null, and properly aligned to construct a slice from it.
The written parameter must not exceed the length of the slice.
The free parameter must be such that written + free does not exceed the length of the
slice.
Sourcepub const fn position(&self) -> usize
pub const fn position(&self) -> usize
Returns how many symbols have been written so far.
This can also be interpreted as the position of the next element to write into the buffer.
Initially this will be 0. If you write n symbols in the
callback and then return, the next time the callback is called,
the position will always be n.
If you then encode m more symbols, the next callback will always
be called with position n + m, and so on.
In other words, the position is preserved across callback invocations.
The only exception is when the encoder is reset,
(e.g. to beging a new transaction) in which case the position
will always restart at 0.
Sourcepub fn write_all(&mut self, symbols: &[Symbol]) -> Result<(), NotEnoughSpace>
pub fn write_all(&mut self, symbols: &[Symbol]) -> Result<(), NotEnoughSpace>
Tries to write all symbols to the buffer.
§Errors
If there is not enough space, it will not write anything and return NotEnoughSpace
to indicate that the buffer is too small.
Sourcepub fn as_mut_slice(&mut self) -> &mut [Symbol]
pub fn as_mut_slice(&mut self) -> &mut [Symbol]
Returns the underlying slice of symbols that have been written so far.