pub struct IndexVec<I: Idx, T> { /* private fields */ }Expand description
A dense vector indexed by ID types.
This provides O(1) access and storage for dense ID-indexed data.
Implementations§
Source§impl<I: Idx, T> IndexVec<I, T>
impl<I: Idx, T> IndexVec<I, T>
Sourcepub fn with_capacity(n: usize) -> Self
pub fn with_capacity(n: usize) -> Self
Create a new IndexVec with pre-allocated capacity.
Sourcepub fn push(&mut self, v: T) -> Result<I, IndexedVecError>
pub fn push(&mut self, v: T) -> Result<I, IndexedVecError>
Push an element and return its ID.
Returns an error if the length would exceed the maximum representable by the ID type.
Sourcepub fn get(&self, idx: I) -> Option<&T>
pub fn get(&self, idx: I) -> Option<&T>
Get an element by ID, returning None if the ID is out of bounds.
Sourcepub fn into_inner(self) -> Vec<T>
pub fn into_inner(self) -> Vec<T>
Consume this IndexVec and return the underlying Vec.
Sourcepub fn swap_remove(&mut self, index: usize) -> T
pub fn swap_remove(&mut self, index: usize) -> T
Remove an element at the specified index and return it.
Trait Implementations§
Source§impl<'a, I: Idx, T> IntoIterator for &'a IndexVec<I, T>
impl<'a, I: Idx, T> IntoIterator for &'a IndexVec<I, T>
Source§impl<I: Idx, T> IntoIterator for IndexVec<I, T>
impl<I: Idx, T> IntoIterator for IndexVec<I, T>
Source§impl<I, T> LookupByIdx<I, T> for IndexVec<I, T>where
I: Idx,
impl<I, T> LookupByIdx<I, T> for IndexVec<I, T>where
I: Idx,
impl<I: Eq + Idx, T: Eq> Eq for IndexVec<I, T>
impl<I: Idx, T> StructuralPartialEq for IndexVec<I, T>
Auto Trait Implementations§
impl<I, T> Freeze for IndexVec<I, T>
impl<I, T> RefUnwindSafe for IndexVec<I, T>where
I: RefUnwindSafe,
T: RefUnwindSafe,
impl<I, T> Send for IndexVec<I, T>
impl<I, T> Sync for IndexVec<I, T>
impl<I, T> Unpin for IndexVec<I, T>
impl<I, T> UnwindSafe for IndexVec<I, T>where
I: UnwindSafe,
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