dyn_stack

Struct DynStack

source
pub struct DynStack { /* private fields */ }
Expand description

Stack wrapper around a buffer of uninitialized bytes.

Implementations§

source§

impl DynStack

source

pub fn new(buffer: &mut [MaybeUninit<u8>]) -> &mut Self

Returns a new DynStack from the provided memory buffer.

source

pub fn new_any<T>(buffer: &mut [MaybeUninit<T>]) -> &mut Self

Returns a new DynStack from the provided memory buffer.

source

pub fn can_hold(&self, alloc_req: StackReq) -> bool

Returns true if the stack can hold an allocation with the given size and alignment requirements.

source

pub fn len_bytes(&self) -> usize

Returns the number of bytes that this stack can hold.

source

pub fn as_ptr(&self) -> *const u8

Returns a pointer to the (possibly uninitialized) stack memory.

source

pub fn make_aligned_uninit<T>( &mut self, size: usize, align: usize, ) -> (DynArray<'_, MaybeUninit<T>>, &mut Self)

Returns a new aligned and uninitialized DynArray and a stack over the remainder of the buffer.

§Panics

Panics if the stack isn’t large enough to allocate the array.

source

pub fn make_aligned_with<T>( &mut self, size: usize, align: usize, f: impl FnMut(usize) -> T, ) -> (DynArray<'_, T>, &mut Self)

Returns a new aligned DynArray, initialized with the provided function, and a stack over the remainder of the buffer.

§Panics

Panics if the stack isn’t large enough to allocate the array, or if the provided function panics.

source

pub fn make_uninit<T>( &mut self, size: usize, ) -> (DynArray<'_, MaybeUninit<T>>, &mut Self)

Returns a new uninitialized DynArray and a stack over the remainder of the buffer.

§Panics

Panics if the stack isn’t large enough to allocate the array.

source

pub fn make_with<T>( &mut self, size: usize, f: impl FnMut(usize) -> T, ) -> (DynArray<'_, T>, &mut Self)

Returns a new DynArray, initialized with the provided function, and a stack over the remainder of the buffer.

§Panics

Panics if the stack isn’t large enough to allocate the array, or if the provided function panics.

source

pub fn collect_aligned<I: IntoIterator>( &mut self, align: usize, iter: I, ) -> (DynArray<'_, I::Item>, &mut Self)

Returns a new aligned DynArray, initialized with the provided iterator, and a stack over the remainder of the buffer.
If there isn’t enough space for all the iterator items, then the returned array only contains the first elements that fit into the stack.

§Panics

Panics if the provided iterator panics.

source

pub fn collect<I: IntoIterator>( &mut self, iter: I, ) -> (DynArray<'_, I::Item>, &mut Self)

Returns a new DynArray, initialized with the provided iterator, and a stack over the remainder of the buffer.
If there isn’t enough space for all the iterator items, then the returned array only contains the first elements that fit into the stack.

§Panics

Panics if the provided iterator panics.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more