Struct mnemos_alloc::containers::ArrayBuf
source · pub struct ArrayBuf<T> {
ptr: NonNull<UnsafeCell<MaybeUninit<T>>>,
len: usize,
}
Expand description
A spooky owned array type
This type represents ownership of essentially an UnsafeCell<MaybeUninit<[T]>>
.
It is intended as a low level building block for things like bbqueue and other data
structures that need to own a specific number of items, and would like to set their
own safety invariants, without manually using alloc
.
Fields§
§ptr: NonNull<UnsafeCell<MaybeUninit<T>>>
§len: usize
Implementations§
source§impl<T> ArrayBuf<T>
impl<T> ArrayBuf<T>
sourcefn layout(len: usize) -> Layout
fn layout(len: usize) -> Layout
Gets the layout for len
items
Panics if creating the layout would fail (e.g. too large for the platform)
sourcepub fn try_new_uninit(len: usize) -> Option<Self>
pub fn try_new_uninit(len: usize) -> Option<Self>
Try to allocate a new ArrayBuf with storage for len
items.
Returns None if the allocation does not succeed immediately.
Panics if the len is zero, or large enough that creating the layout would fail
sourcepub async fn new_uninit(len: usize) -> Self
pub async fn new_uninit(len: usize) -> Self
Try to allocate a new ArrayBuf with storage for len
items.
Will not return until allocation succeeds.
Panics if the len is zero, or large enough that creating the layout would fail
sourcepub fn ptrlen(&self) -> (NonNull<UnsafeCell<MaybeUninit<T>>>, usize)
pub fn ptrlen(&self) -> (NonNull<UnsafeCell<MaybeUninit<T>>>, usize)
Obtain a pointer to the heap allocated storage, as well as the length of items
This does NOT leak the heap allocation. The returned pointer has the lifetime
of this ArrayBuf
.