pub struct IndexVec<I: Idx, T> { /* private fields */ }Expand description
A vector keyed by I instead of by usize.
The whole point is push: it appends and returns the
index it assigned, so a producer names a node at the moment it creates one
and never recomputes that name. Indexing panics on an out-of-range index the
way Vec does, because an index of the wrong domain cannot be constructed
in the first place and an index of the right domain that is out of range is
a defect in the producer.
PhantomData<fn(I)> keeps I out of drop-checking and out of auto-trait
inference: an IndexVec<I, T> is Send/Sync exactly when T is.
Implementations§
Source§impl<I: Idx, T> IndexVec<I, T>
impl<I: Idx, T> IndexVec<I, T>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Returns an empty vector with room for capacity elements.
Sourcepub fn next_index(&self) -> I
pub fn next_index(&self) -> I
Returns the index the next push will assign.
Sourcepub fn get(&self, index: I) -> Option<&T>
pub fn get(&self, index: I) -> Option<&T>
Returns the element index names, or None when it is out of range.
Sourcepub fn get_mut(&mut self, index: I) -> Option<&mut T>
pub fn get_mut(&mut self, index: I) -> Option<&mut T>
Returns the element index names mutably, or None when it is out of
range.
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, T> ⓘ
pub fn iter_mut(&mut self) -> IterMut<'_, T> ⓘ
Returns the elements in position order, mutably.
Sourcepub fn iter_enumerated(
&self,
) -> impl DoubleEndedIterator<Item = (I, &T)> + ExactSizeIterator
pub fn iter_enumerated( &self, ) -> impl DoubleEndedIterator<Item = (I, &T)> + ExactSizeIterator
Returns each element paired with the index naming it.
Sourcepub fn iter_enumerated_mut(
&mut self,
) -> impl DoubleEndedIterator<Item = (I, &mut T)> + ExactSizeIterator
pub fn iter_enumerated_mut( &mut self, ) -> impl DoubleEndedIterator<Item = (I, &mut T)> + ExactSizeIterator
Returns each element paired with the index naming it, mutably.
Sourcepub fn indices(&self) -> impl DoubleEndedIterator<Item = I> + ExactSizeIterator
pub fn indices(&self) -> impl DoubleEndedIterator<Item = I> + ExactSizeIterator
Returns every index this vector currently names.
Sourcepub fn as_mut_slice(&mut self) -> &mut [T]
pub fn as_mut_slice(&mut self) -> &mut [T]
Returns the elements as a plain mutable slice.