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_mutmethods must return pointers to the same data - The pointer returned by
as_mutmust be stable until either a call toextendor 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.) extendmust not change any contained data (but may extend with unspecified values)
Required Associated Types§
Required Methods§
Sourcefn as_ref(&self) -> &[MaybeUninit<Self::Inner>]
fn as_ref(&self) -> &[MaybeUninit<Self::Inner>]
Get the buffer slice as an immutable borrow
Sourcefn as_mut(&mut self) -> &mut [MaybeUninit<Self::Inner>]
fn as_mut(&mut self) -> &mut [MaybeUninit<Self::Inner>]
Get the buffer slice as a mutable borrow
Provided Methods§
Sourcefn round_to_words(bytes: usize) -> usize
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: Pod> DataBuf for Vec<MaybeUninit<T>>
Available on crate feature alloc only.Vector backed structures, can be used to auto-grow the allocation
impl<T: Pod> DataBuf for Vec<MaybeUninit<T>>
Available on crate feature
alloc only.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§impl<T: Pod, const N: usize> DataBuf for [MaybeUninit<T>; N]
Available on crate feature const_generics only.Array-specific impl
impl<T: Pod, const N: usize> DataBuf for [MaybeUninit<T>; N]
Available on crate feature
const_generics only.Array-specific impl