pub struct TaggedVec<Index, Value> { /* private fields */ }Expand description
A Vec wrapper that allows indexing only via the given Index type.
For actual operation, Index must implement From<usize> and Into<usize>.
Implementations§
Source§impl<Index, Value> TaggedVec<Index, Value>
impl<Index, Value> TaggedVec<Index, Value>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new empty TaggedVec with at least the specified capacity.
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the total number of elements the TaggedVec can hold without reallocating.
Sourcepub fn as_untagged_slice(&self) -> &[Value]
pub fn as_untagged_slice(&self) -> &[Value]
Returns the untagged slice of the Vec underlying this TaggedVec.
Sourcepub fn as_untagged_mut_slice(&mut self) -> &mut [Value]
pub fn as_untagged_mut_slice(&mut self) -> &mut [Value]
Returns the untagged mutable slice of the Vec underlying this TaggedVec.
Sourcepub fn push(&mut self, value: Value) -> Index
pub fn push(&mut self, value: Value) -> Index
Inserts the given value at the back of the TaggedVec, returning its index.
Sourcepub fn push_in_place(&mut self, value: impl FnOnce(Index) -> Value) -> Index
pub fn push_in_place(&mut self, value: impl FnOnce(Index) -> Value) -> Index
Insert a single value into the TaggedVec by constructing it in place.
This method allows to create the value while already knowing its index. Returns the index.
Sourcepub fn pop(&mut self) -> Option<(Index, Value)>
pub fn pop(&mut self) -> Option<(Index, Value)>
Removes the value at the back of the TaggedVec and returns it with its index.
Sourcepub fn insert(&mut self, index: Index, value: Value)
pub fn insert(&mut self, index: Index, value: Value)
Inserts the given value at position index, shifting all existing values in range index.. one position to the right.
Sourcepub fn splice<I: IntoIterator<Item = Value>>(
&mut self,
range: impl RangeBounds<Index>,
replace_with: I,
) -> Splice<'_, I::IntoIter>
pub fn splice<I: IntoIterator<Item = Value>>( &mut self, range: impl RangeBounds<Index>, replace_with: I, ) -> Splice<'_, I::IntoIter>
See Vec::splice.
Sourcepub fn retain(&mut self, f: impl FnMut(&Value) -> bool)
pub fn retain(&mut self, f: impl FnMut(&Value) -> bool)
Retains only the values specified by the predicate.
In other words, remove all values v for which f(&v) returns false.
This method operates in place, visiting each value exactly once in the original order, and preserves the order of the retained values.
Sourcepub fn remove_multi(&mut self, indices: impl IntoIterator<Item = Index>)
pub fn remove_multi(&mut self, indices: impl IntoIterator<Item = Index>)
Removes the elements at the specified indices, shifting other elements to the left to fill gaps as required.
The provided indices must be sorted.
Sourcepub fn get(&self, index: Index) -> Option<&Value>
pub fn get(&self, index: Index) -> Option<&Value>
Returns a reference to the value at the given index, or None if the index is out of bounds.
Sourcepub fn iter(
&self,
range: impl RangeBounds<Index>,
) -> impl DoubleEndedIterator<Item = (Index, &Value)> + ExactSizeIterator
pub fn iter( &self, range: impl RangeBounds<Index>, ) -> impl DoubleEndedIterator<Item = (Index, &Value)> + ExactSizeIterator
Returns an iterator over references to the entries of the TaggedVec.
The range specifies which subset of the entries to iterate over.
Iterating over a partial range with this argument is more efficient than iterating over the whole vector and skipping the unwanted entries, because the returned iterator does not support the skip optimisation.
Sourcepub fn iter_mut(
&mut self,
range: impl RangeBounds<Index>,
) -> impl DoubleEndedIterator<Item = (Index, &mut Value)> + ExactSizeIterator
pub fn iter_mut( &mut self, range: impl RangeBounds<Index>, ) -> impl DoubleEndedIterator<Item = (Index, &mut Value)> + ExactSizeIterator
Returns an iterator over mutable references to the entries of the TaggedVec.
The range specifies which subset of the entries to iterate over.
Iterating over a partial range with this argument is more efficient than iterating over the whole vector and skipping the unwanted entries, because the returned iterator does not support the skip optimisation.
Sourcepub fn iter_values(&self) -> Iter<'_, Value>
pub fn iter_values(&self) -> Iter<'_, Value>
Returns an iterator over references to the values of the TaggedVec.
Sourcepub fn iter_values_mut(&mut self) -> IterMut<'_, Value>
pub fn iter_values_mut(&mut self) -> IterMut<'_, Value>
Returns an iterator over mutable references to the values of the TaggedVec.
Sourcepub fn iter_indices(
&self,
range: impl RangeBounds<Index>,
) -> IndexIterator<Index> ⓘ
pub fn iter_indices( &self, range: impl RangeBounds<Index>, ) -> IndexIterator<Index> ⓘ
Returns an iterator over the indices of the TaggedVec.
The range specifies which subset of the entries to iterate over.
Iterating over a partial range with this argument is more efficient than iterating over the whole vector and skipping the unwanted entries, because the returned iterator does not support the skip optimisation.
Sourcepub fn into_iter(
self,
range: impl RangeBounds<Index>,
) -> impl DoubleEndedIterator<Item = (Index, Value)> + ExactSizeIterator
pub fn into_iter( self, range: impl RangeBounds<Index>, ) -> impl DoubleEndedIterator<Item = (Index, Value)> + ExactSizeIterator
Consumes the TaggedVec, returning an iterator over the entries.
The range specifies which subset of the entries to iterate over.
Iterating over a partial range with this argument is more efficient than iterating over the whole vector and skipping the unwanted entries, because the returned iterator does not support the skip optimisation.
Sourcepub fn into_values_iter(self) -> IntoIter<Value>
pub fn into_values_iter(self) -> IntoIter<Value>
Consumes the TaggedVec, returning an iterator over the values.
Trait Implementations§
Source§impl<Index, Value> Extend<Value> for TaggedVec<Index, Value>
impl<Index, Value> Extend<Value> for TaggedVec<Index, Value>
Source§fn extend<T: IntoIterator<Item = Value>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = Value>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)