pub struct FixedCapacityVec<T, const N: usize> { /* private fields */ }
Expand description

Like Vec with a capacity fixed at compile time

When full, can be converted without copying into Box<[T; N]>, using TryFrom.

All of the following types store only the actual buffer on the heap, and they are interconvertible without copying the data.

TypeSize and representation (as eg on stack)Full?Mutability
Vec3 words: pointer, length, capacitymaybeindefinitely appendable
Box<[T]>2 words: pointer, length = capacityalwayslength fixed at runtime
FixedCapacityVec<[T; N]>2 words: pointer, lengthmaybeappendable, but capacity fixed at compile time
Box<[T; N]>1 word: pointeralwayslength fixed at compile time

Implementations§

source§

impl<T, const N: usize> FixedCapacityVec<T, N>

source

pub fn new() -> Self

Create a new empty FixedCapacityVec, capable of holding up to N values of type T

source

pub fn len(&self) -> usize

Return the number of values stored so far

source

pub fn is_empty(&self) -> bool

Returns true iff the FixedCapacityVec is empty

source

pub fn is_full(&self) -> bool

Returns true iff the FixedCapacityVec is full - ie, it has N elements

source

pub fn push(&mut self, item: T)

Append an element

Panics

Panics if the FixedCapacityVec is full, ie if it already contains N elements

Trait Implementations§

source§

impl<T, const N: usize> Drop for FixedCapacityVec<T, N>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<T, const N: usize> TryFrom<FixedCapacityVec<T, N>> for Box<[T; N]>

Convert a full FixedCapacityVec into a boxed array.

If the FixedCapacityVec isn’t full, it is returned as the Err

§

type Error = FixedCapacityVec<T, N>

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

fn try_from( fcvec: FixedCapacityVec<T, N> ) -> Result<Box<[T; N]>, FixedCapacityVec<T, N>>

Performs the conversion.
source§

impl<T: RefUnwindSafe, const N: usize> RefUnwindSafe for FixedCapacityVec<T, N>

source§

impl<T: Send, const N: usize> Send for FixedCapacityVec<T, N>

source§

impl<T: Sync, const N: usize> Sync for FixedCapacityVec<T, N>

source§

impl<T: UnwindSafe, const N: usize> UnwindSafe for FixedCapacityVec<T, N>

Auto Trait Implementations§

§

impl<T, const N: usize> Unpin for FixedCapacityVec<T, N>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.