Skip to main content

SymbolBuffer

Struct SymbolBuffer 

Source
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>

Source

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.

Source

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.

Source

pub fn remaining(&self) -> usize

Returns how many more symbols can be written to the buffer.

Source

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.

Source

pub fn as_mut_slice(&mut self) -> &mut [Symbol]

Returns the underlying slice of symbols that have been written so far.

Trait Implementations§

Source§

impl<'a> Debug for SymbolBuffer<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for SymbolBuffer<'a>

§

impl<'a> RefUnwindSafe for SymbolBuffer<'a>

§

impl<'a> Send for SymbolBuffer<'a>

§

impl<'a> Sync for SymbolBuffer<'a>

§

impl<'a> Unpin for SymbolBuffer<'a>

§

impl<'a> UnsafeUnpin for SymbolBuffer<'a>

§

impl<'a> !UnwindSafe for SymbolBuffer<'a>

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.