pub struct IdVec<ID: Identifier, T> { /* private fields */ }
Expand description
Similar to Vec except that it is indexed using an Id rather than an usize index. if the stored type implements Default, IdVec can also use the set(…) method which can grow the vector to accomodate for the requested id.
Implementations§
source§impl<ID: Identifier, T> IdVec<ID, T>
impl<ID: Identifier, T> IdVec<ID, T>
sourcepub fn with_capacity(size: ID::Handle) -> Self
pub fn with_capacity(size: ID::Handle) -> Self
Create an IdVec with preallocated storage
sourcepub fn as_mut_slice(&mut self) -> MutIdSlice<'_, ID, T>
pub fn as_mut_slice(&mut self) -> MutIdSlice<'_, ID, T>
Extracts a mutable slice containing the entire vector.
pub fn range(&self, ids: IdRange<ID::Tag, ID::Handle>) -> IdSlice<'_, ID, T>
pub fn mut_range( &mut self, ids: IdRange<ID::Tag, ID::Handle> ) -> MutIdSlice<'_, ID, T>
pub fn range_from(&self, id: ID) -> IdSlice<'_, ID, T>
pub fn mut_range_from(&mut self, id: ID) -> MutIdSlice<'_, ID, T>
pub fn range_to(&self, id: ID) -> IdSlice<'_, ID, T>
pub fn mut_range_to(&mut self, id: ID) -> MutIdSlice<'_, ID, T>
pub fn range_to_inclusive(&self, id: ID) -> IdSlice<'_, ID, T>
pub fn mut_range_to_inclusive(&mut self, id: ID) -> MutIdSlice<'_, ID, T>
sourcepub fn nth(&self, idx: ID::Handle) -> &T
pub fn nth(&self, idx: ID::Handle) -> &T
Return the nth element of the IdVec using an usize index rather than an Id (à la Vec).
sourcepub fn nth_mut(&mut self, idx: ID::Handle) -> &mut T
pub fn nth_mut(&mut self, idx: ID::Handle) -> &mut T
Return the nth element of the IdVec using an usize index rather than an Id (à la Vec).
sourcepub fn push(&mut self, elt: T) -> ID
pub fn push(&mut self, elt: T) -> ID
Add an element to the IdVec and return its Id. This method can cause the storage to be reallocated.
sourcepub fn insert(&mut self, id: ID, elt: T)
pub fn insert(&mut self, id: ID, elt: T)
Inserts an element at position id
within the vector, shifting all elements
after it to the right.
sourcepub fn insert_slice(&mut self, id: ID, elts: &[T])where
T: Clone,
pub fn insert_slice(&mut self, id: ID, elts: &[T])where
T: Clone,
Insert several elements by cloning them starting at position ’id` and shifting all elements after them to the right.
sourcepub fn insert_id_slice(&mut self, id: ID, elts: IdSlice<'_, ID, T>)where
T: Clone,
pub fn insert_id_slice(&mut self, id: ID, elts: IdSlice<'_, ID, T>)where
T: Clone,
Insert several elements by cloning them starting at position ’id` and shifting all elements after them to the right.
sourcepub fn extend_from_slice(&mut self, elts: &[T])where
T: Clone,
pub fn extend_from_slice(&mut self, elts: &[T])where
T: Clone,
Clones and appends all elements in a slice to the vector.
sourcepub fn extend_from_id_slice(&mut self, elts: IdSlice<'_, ID, T>)where
T: Clone,
pub fn extend_from_id_slice(&mut self, elts: IdSlice<'_, ID, T>)where
T: Clone,
Clones and appends all elements in a slice to the vector.
sourcepub fn reserve(&mut self, additional: ID::Handle)
pub fn reserve(&mut self, additional: ID::Handle)
Reserves capacity for at least additional more elements to be inserted in the given vector.
sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrinks the capacity of the vector as much as possible.
sourcepub fn remove(&mut self, index: ID) -> T
pub fn remove(&mut self, index: ID) -> T
Removes and returns the element at position index within the vector, shifting all elements after it to the left.
sourcepub fn swap_remove(&mut self, index: ID) -> T
pub fn swap_remove(&mut self, index: ID) -> T
Removes an element from the vector and returns it. The removed element is replaced by the last element of the vector.