FlatVec

Struct FlatVec 

Source
pub struct FlatVec<T, IndexTy: Default, BackingTy, const INDEX_INLINE_LEN: usize> { /* private fields */ }
Expand description

An indirection-collapsing container with minimal allocation

Read as “An internally-flattening Vec of T, indexed by IndexTy, where each T is stored as a slice of BackingTy” For simple use cases, you may want a type alias for FlatVec<T, usize, u8, 3>, but under some workloads it is very profitable to pick a smaller IndexTy, possibly even u8, and a corresponding inline capacity.

Implementations§

Source§

impl<'a, T: 'a, IndexTy, BackingTy, const INDEX_INLINE_LEN: usize> FlatVec<T, IndexTy, BackingTy, INDEX_INLINE_LEN>
where IndexTy: Default + TryFrom<usize> + Copy + Sub, usize: TryFrom<IndexTy>, <IndexTy as TryFrom<usize>>::Error: Debug, <usize as TryFrom<IndexTy>>::Error: Debug,

Source

pub fn new() -> Self

Create a new FlatVec, this is just an alias for the Default implementation.

Source

pub fn len(&self) -> usize

Returns the number of T in a FlatVec<T>.

Source

pub fn data_len(&self) -> usize

Returns the number of BackingTy used to store the elements of a FlatVec. This does not necessarily correlate with storage used to store the indices.

Source

pub fn data_capacity(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Returns true if the len is 0.

Source

pub fn clear(&mut self)

Source

pub fn push<Source>(&mut self, input: Source)
where Source: IntoFlat<BackingTy, T>,

Appends an element to the back of the collection.

Source

pub fn get<Dest>(&'a self, index: usize) -> Option<Dest>
where Dest: FromFlat<'a, BackingTy, T> + 'a,

Construct a Dest from the indexth element’s stored representation.

Source

pub fn iter<Dest>(&'a self) -> impl Iterator<Item = Dest> + 'a
where Dest: FromFlat<'a, BackingTy, T> + 'a,

Returns an iterator that constructs a Dest from each element’s stored representation.

Source§

impl<'a, T: 'a, IndexTy, BackingTy, const INDEX_INLINE_LEN: usize> FlatVec<T, IndexTy, BackingTy, INDEX_INLINE_LEN>
where IndexTy: Default + TryFrom<usize> + Copy + Sub, usize: TryFrom<IndexTy>, <IndexTy as TryFrom<usize>>::Error: Debug, <usize as TryFrom<IndexTy>>::Error: Debug, BackingTy: Copy,

Source

pub fn remove(&mut self, index: usize)

Removes the indexth element of a FlatVec. This function is O(self.len() + self.data_len()).

Trait Implementations§

Source§

impl<T: Clone, IndexTy: Clone + Default, BackingTy: Clone, const INDEX_INLINE_LEN: usize> Clone for FlatVec<T, IndexTy, BackingTy, INDEX_INLINE_LEN>

Source§

fn clone(&self) -> FlatVec<T, IndexTy, BackingTy, INDEX_INLINE_LEN>

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, IndexTy, BackingTy, const INDEX_INLINE_LEN: usize> Debug for FlatVec<T, IndexTy, BackingTy, INDEX_INLINE_LEN>
where IndexTy: Debug + Default, BackingTy: Debug,

Source§

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

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

impl<T, IndexTy, BackingTy, const INDEX_INLINE_LEN: usize> Default for FlatVec<T, IndexTy, BackingTy, INDEX_INLINE_LEN>
where IndexTy: Default,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T, IndexTy, BackingTy, const INDEX_INLINE_LEN: usize> Freeze for FlatVec<T, IndexTy, BackingTy, INDEX_INLINE_LEN>
where IndexTy: Freeze,

§

impl<T, IndexTy, BackingTy, const INDEX_INLINE_LEN: usize> RefUnwindSafe for FlatVec<T, IndexTy, BackingTy, INDEX_INLINE_LEN>
where T: RefUnwindSafe, IndexTy: RefUnwindSafe, BackingTy: RefUnwindSafe,

§

impl<T, IndexTy, BackingTy, const INDEX_INLINE_LEN: usize> Send for FlatVec<T, IndexTy, BackingTy, INDEX_INLINE_LEN>
where T: Send, BackingTy: Send, IndexTy: Send,

§

impl<T, IndexTy, BackingTy, const INDEX_INLINE_LEN: usize> Sync for FlatVec<T, IndexTy, BackingTy, INDEX_INLINE_LEN>
where T: Sync, BackingTy: Sync, IndexTy: Sync,

§

impl<T, IndexTy, BackingTy, const INDEX_INLINE_LEN: usize> Unpin for FlatVec<T, IndexTy, BackingTy, INDEX_INLINE_LEN>
where T: Unpin, IndexTy: Unpin,

§

impl<T, IndexTy, BackingTy, const INDEX_INLINE_LEN: usize> UnwindSafe for FlatVec<T, IndexTy, BackingTy, INDEX_INLINE_LEN>
where T: UnwindSafe, BackingTy: UnwindSafe, IndexTy: 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.