FixedCapacityVec

Struct FixedCapacityVec 

Source
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: usize

Number of elements in Self. Also an index, pointing always to the first unused slot in Self::elements.

Implementations§

Source§

impl<T> FixedCapacityVec<T>

Source

pub fn with_capacity(capacity: usize) -> Self

Construct new Self, holding up to capacity elements of type T

Source

pub const fn is_empty(&self) -> bool

Check if the Self is empty

Source

pub const fn is_full(&self) -> bool

Check if the Self is full

Source

pub const fn len(&self) -> usize

Get the Self is height.

Source

pub const fn capacity(&self) -> usize

Get the maximum number of elements that fit into Self.

Source

pub unsafe fn push_unchecked(&mut self, value: T)

Push a value to the end of Self

§Safety
  • Causes UB if Self is already full.
  • Causes UB if Self has a capacity equal to usize::MAX
Source

pub fn push(&mut self, value: T) -> Result<(), FullContainerError>

Push a value to the end of Self

Source

pub unsafe fn pop_unchecked(&mut self) -> T

Pop a value from Self’s top/tail

§Safety

Causes UB if the stack is empty.

Source

pub fn pop(&mut self) -> Result<T, EmptyContainerError>

Pop a value from Self’s top/tail

Source

pub unsafe fn peek_unchecked(&self) -> &T

Peek at the topmost/last value from Self

§Safety

Causes UB if the stack is empty.

Source

pub fn peek(&self) -> Result<&T, EmptyContainerError>

Peek at the topmost/last value from Self

Source

pub fn get(&self, idx: usize) -> Option<&T>

Get a shared ref to the nth element in Self

Source

pub fn get_mut(&mut self, idx: usize) -> Option<&mut T>

Get a mut ref to the nth element in Self

Source§

impl<T: Clone> FixedCapacityVec<T>

Source

pub fn push_from_slice( &mut self, values: &[T], ) -> Result<(), FullContainerError>

Push from a slice into Self, appending after the last/topmost element

Source

pub fn pop_into_slice( &mut self, n: usize, ) -> Result<impl Deref<Target = [T]> + '_, EmptyContainerError>

Pop n elements from Self into a slice. The topmost/last element of Self will become the slice’s last element.

Source§

impl<T: Copy> FixedCapacityVec<T>

Source

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, Self will contain remove_count fewer elements
  • keep_count topmost elements will be identical before and after the operation
  • all elements below the remove_count + keep_count topmost stack entry remain

Trait Implementations§

Source§

impl<T: Clone> Clone for FixedCapacityVec<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for FixedCapacityVec<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Drop for FixedCapacityVec<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for FixedCapacityVec<T>

§

impl<T> RefUnwindSafe for FixedCapacityVec<T>
where T: RefUnwindSafe,

§

impl<T> Send for FixedCapacityVec<T>
where T: Send,

§

impl<T> Sync for FixedCapacityVec<T>
where T: Sync,

§

impl<T> Unpin for FixedCapacityVec<T>

§

impl<T> UnwindSafe for FixedCapacityVec<T>
where T: UnwindSafe,

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
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.