Trait 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)

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

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

Source§

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<(), ()>

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);
}
Source§

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, const N: usize> DataBuf for [MaybeUninit<T>; N]

Array-specific impl

Source§

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<(), ()>

Implementors§

Source§

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

Source§

type Inner = T

Source§

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

Source§

type Inner = T