pub struct Stack<T> { /* private fields */ }Expand description
Allocate memory but never free it until the entire Stack is dropped.
Items popped from the stack are marked as Empty so the memory is reused.
Implementations§
Source§impl<T> Stack<T>
impl<T> Stack<T>
Sourcepub fn next_index(&self) -> usize
pub fn next_index(&self) -> usize
Get the next index that will be written to
Sourcepub fn with_capacity(cap: usize) -> Self
pub fn with_capacity(cap: usize) -> Self
Create a stack with an initial capacity. This will fill the stack with empty entries
pub fn get(&self, index: usize) -> Option<&T>
Sourcepub fn swap(&mut self, index: usize, new_value: T) -> T
pub fn swap(&mut self, index: usize, new_value: T) -> T
Swap out a value in the stack at a given location.
§Panics
Panics if the index contains an empty slot
Sourcepub fn iter(&self) -> impl DoubleEndedIterator<Item = &T> + '_
pub fn iter(&self) -> impl DoubleEndedIterator<Item = &T> + '_
Create an iterator over the values on the stack
Sourcepub fn iter_mut(&mut self) -> impl DoubleEndedIterator<Item = &mut T> + '_
pub fn iter_mut(&mut self) -> impl DoubleEndedIterator<Item = &mut T> + '_
Create an iterator over the values on the stack
Sourcepub fn drain(
&mut self,
) -> StackDrain<T, impl DoubleEndedIterator<Item = T> + '_> ⓘ
pub fn drain( &mut self, ) -> StackDrain<T, impl DoubleEndedIterator<Item = T> + '_> ⓘ
A draining iterator over the values on the stack.
let mut stack = Stack::empty();
stack.push(1);
stack.push(2);
assert_eq!(stack.drain().next(), Some(2));
assert!(stack.is_empty());Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
The stack will contains allocated memory even if is_empty returns true.k
pub fn len(&self) -> usize
pub fn reserve(&mut self, len: usize)
Sourcepub fn drain_into(&mut self, local: &mut Stack<T>)
pub fn drain_into(&mut self, local: &mut Stack<T>)
Drain all the values into another stack.
Prefer Self::drain_copy_into if T is Copy.
It might be marginally faster.
Trait Implementations§
Source§impl<T> FromIterator<T> for Stack<T>
impl<T> FromIterator<T> for Stack<T>
Source§fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
Creates a value from an iterator. Read more
Auto Trait Implementations§
impl<T> Freeze for Stack<T>
impl<T> RefUnwindSafe for Stack<T>where
T: RefUnwindSafe,
impl<T> Send for Stack<T>where
T: Send,
impl<T> Sync for Stack<T>where
T: Sync,
impl<T> Unpin for Stack<T>where
T: Unpin,
impl<T> UnsafeUnpin for Stack<T>
impl<T> UnwindSafe for Stack<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more