pub struct FixedCapacityVec<T> {
elements: Box<[MaybeUninit<T>]>,
len: usize,
}Fields§
§elements: Box<[MaybeUninit<T>]>A contiguous, non-reallocating, heap allocated vector. Behaves like a subset of
alloc::vec::Vec, cleansed of any operation that reallocates. Backed by via boxed
slice containing elements of type MaybeUninit<T>. The maximum size (pendant to
alloc::vec::Vec::capacity) is determined at creation and remains unchanged over the
lifetime of Self. Nonetheless a variable amount of T can be kept within Self, just
never more than the maximum size passed to the constructor.
This can be used as a stack, in which case the first element (forming the bottom of the
stack) is at index 0, and new elements grow towards Self’s end. The last element
(self.stack[self.stack.len() - 1] is the topmost possible entry.
len: usizeNumber of elements in Self. Also an index, pointing always to the first unused slot in
Self::elements.
Implementations§
Source§impl<T> FixedCapacityVec<T>
impl<T> FixedCapacityVec<T>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Construct new Self, holding up to capacity elements of type T
Sourcepub unsafe fn push_unchecked(&mut self, value: T)
pub unsafe fn push_unchecked(&mut self, value: T)
Sourcepub fn push(&mut self, value: T) -> Result<(), FullContainerError>
pub fn push(&mut self, value: T) -> Result<(), FullContainerError>
Push a value to the end of Self
Sourcepub unsafe fn pop_unchecked(&mut self) -> T
pub unsafe fn pop_unchecked(&mut self) -> T
Sourcepub fn pop(&mut self) -> Result<T, EmptyContainerError>
pub fn pop(&mut self) -> Result<T, EmptyContainerError>
Pop a value from Self’s top/tail
Sourcepub unsafe fn peek_unchecked(&self) -> &T
pub unsafe fn peek_unchecked(&self) -> &T
Source§impl<T: Clone> FixedCapacityVec<T>
impl<T: Clone> FixedCapacityVec<T>
Sourcepub fn push_from_slice(
&mut self,
values: &[T],
) -> Result<(), FullContainerError>
pub fn push_from_slice( &mut self, values: &[T], ) -> Result<(), FullContainerError>
Push from a slice into Self, appending after the last/topmost element
Sourcepub fn pop_into_slice(
&mut self,
n: usize,
) -> Result<impl Deref<Target = [T]> + '_, EmptyContainerError>
pub fn pop_into_slice( &mut self, n: usize, ) -> Result<impl Deref<Target = [T]> + '_, EmptyContainerError>
Source§impl<T: Copy> FixedCapacityVec<T>
impl<T: Copy> FixedCapacityVec<T>
Sourcepub fn remove_in_between(&mut self, remove_count: usize, keep_count: usize)
pub fn remove_in_between(&mut self, remove_count: usize, keep_count: usize)
Remove remove_count values from Self, keeping the topmost keep_count values
From the Self, remove remove_count elements, by sliding down the keep_count last/topmost
values remove_count positions forward/towards the bottom.
Effects
- after the operation,
Selfwill containremove_countfewer elements keep_counttopmost elements will be identical before and after the operation- all elements below the
remove_count + keep_counttopmost stack entry remain