Trait stack_dst::DataBuf

source ·
pub unsafe trait DataBuf {
    type Inner: Pod;

    // Required methods
    fn as_ref(&self) -> &[MaybeUninit<Self::Inner>];
    fn as_mut(&mut self) -> &mut [MaybeUninit<Self::Inner>];
    fn extend(&mut self, len: usize) -> Result<(), ()>;

    // Provided method
    fn round_to_words(bytes: usize) -> usize { ... }
}
Expand description

Trait used to represent a data buffer, typically you’ll passs a [usize; N] array.

Can also provide a Vec<T> (if the alloc feature is enabled) which will grow as-needed

UNSAFE: Used by the internal unsafe code, must confor to the following rules

  • The as_ref/as_mut methods must return pointers to the same data
  • The pointer returned by as_mut must be stable until either a call to extend or the value is moved (i.e. let a = foo.as_mut().as_ptr(); let b = foo.as_mut().as_ptr(); assert!(a == b) always holds.)
  • extend must not change any contained data (but may extend with unspecified values)

Required Associated Types§

source

type Inner: Pod

Inner type of the buffer

Required Methods§

source

fn as_ref(&self) -> &[MaybeUninit<Self::Inner>]

Get the buffer slice as an immutable borrow

source

fn as_mut(&mut self) -> &mut [MaybeUninit<Self::Inner>]

Get the buffer slice as a mutable borrow

source

fn extend(&mut self, len: usize) -> Result<(), ()>

Extend the buffer (fallible)

Provided Methods§

source

fn round_to_words(bytes: usize) -> usize

Convert a byte count to a word count (rounding up)

Implementations on Foreign Types§

source§

impl<T: Pod, const N: usize> DataBuf for [MaybeUninit<T>; N]

Array-specific impl

§

type Inner = T

source§

fn as_ref(&self) -> &[MaybeUninit<Self::Inner>]

source§

fn as_mut(&mut self) -> &mut [MaybeUninit<Self::Inner>]

source§

fn extend(&mut self, len: usize) -> Result<(), ()>

source§

impl<T: Pod> DataBuf for Vec<MaybeUninit<T>>

Vector backed structures, can be used to auto-grow the allocation

let mut buf = ::stack_dst::Fifo::<str, Vec<::std::mem::MaybeUninit<u8>>>::new();
buf.push_back_str("Hello world!");
buf.push_back_str("This is a very long string");
buf.push_back_str("The buffer should keep growing as it needs to");
for line in buf.iter() {
  println!("{}", line);
}
§

type Inner = T

source§

fn as_ref(&self) -> &[MaybeUninit<Self::Inner>]

source§

fn as_mut(&mut self) -> &mut [MaybeUninit<Self::Inner>]

source§

fn extend(&mut self, len: usize) -> Result<(), ()>

source§

impl<T, U> DataBuf for &mut Twhere U: Pod, T: DataBuf<Inner = U>,

§

type Inner = <T as DataBuf>::Inner

source§

fn as_ref(&self) -> &[MaybeUninit<Self::Inner>]

source§

fn as_mut(&mut self) -> &mut [MaybeUninit<Self::Inner>]

source§

fn extend(&mut self, len: usize) -> Result<(), ()>

Implementors§

source§

impl<T, N> DataBuf for stack_dst::buffers::ArrayBuf<T, N>where T: Pod, N: ArrayLength<MaybeUninit<T>>,

§

type Inner = T

source§

impl<T, const N: usize> DataBuf for stack_dst::buffers::ConstArrayBuf<T, N>where T: Pod,

§

type Inner = T