devela::all

Trait DstBuf

Source
pub unsafe trait DstBuf {
    type Inner: MemPod;

    // 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  { ... }
}
Available on crate feature unsafe_layout only.
Expand description

Represents the backing buffer for storing dynamically sized types.

§Safety

Must conform 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: MemPod

Inner type of the buffer

Required Methods§

Source

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

Get the buffer slice as shared reference.

Source

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

Get the buffer slice as an exclusive reference.

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> DstBuf for &mut T
where U: MemPod, T: DstBuf<Inner = U>,

Source§

type Inner = <T as DstBuf>::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: MemPod, const CAP: usize> DstBuf for [MaybeUninit<T>; CAP]

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: MemPod> DstBuf for Vec<MaybeUninit<T>>

Available on crate feature alloc only.

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

§Examples

let mut buf = DstQueue::<str, Vec<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§

impl<T: MemPod, const CAP: usize> DstBuf for DstArray<T, CAP>

Source§

type Inner = T