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 toextend
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§
Required Methods§
Sourcefn as_ref(&self) -> &[MaybeUninit<Self::Inner>] ⓘ
fn as_ref(&self) -> &[MaybeUninit<Self::Inner>] ⓘ
Get the buffer slice as shared reference.
Sourcefn as_mut(&mut self) -> &mut [MaybeUninit<Self::Inner>] ⓘ
fn as_mut(&mut self) -> &mut [MaybeUninit<Self::Inner>] ⓘ
Get the buffer slice as an exclusive reference.
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§
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
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);
}