pub struct ValueVec<V: Copy> { /* private fields */ }Expand description
A by-value, ref-less vector with interior mutability. Values of type V can be moved into and out of the vector. We require V to be Copy to avoid subtle soundness issues.
Implementations§
Source§impl<V: Copy> ValueVec<V>
impl<V: Copy> ValueVec<V>
Sourcepub fn with_capacity(cap: usize) -> Self
pub fn with_capacity(cap: usize) -> Self
Creates with capacity.
Sourcepub fn reserve(&self, additional: usize)
pub fn reserve(&self, additional: usize)
Ensures capacity for at least additional more elements.
Sourcepub fn shrink_to_fit(&self)
pub fn shrink_to_fit(&self)
Shrinks the capacity as much as possible.
Sourcepub fn get(&self, index: usize) -> Option<V>
pub fn get(&self, index: usize) -> Option<V>
Returns the value of the element at index, if index is in range. Returns None if index is out of bounds.
This is a bounds-checked variant of ValueVec::at.
Sourcepub fn at(&self, index: usize) -> V
pub fn at(&self, index: usize) -> V
Returns the value at index. Panics if index is out of bounds.
Use ValueVec::get for a bounds-checked version of this method.
Sourcepub fn replace(&self, index: usize, value: V) -> V
pub fn replace(&self, index: usize, value: V) -> V
Moves a value into the slot at index, returning the old value (via move). Panics if index is out of bounds.
Sourcepub fn set(&self, index: usize, value: V)
pub fn set(&self, index: usize, value: V)
Sets the value of the slot at index to value. Panics if index is out of bounds.
Sourcepub fn swap_value(&self, index: usize, value: &mut V)
pub fn swap_value(&self, index: usize, value: &mut V)
Swaps the value at index with the provided one in place. Panics if index is out of bounds.
The existing value ends up in *value.
Sourcepub fn insert(&self, index: usize, value: V)
pub fn insert(&self, index: usize, value: V)
Inserts value at position index, shifting elements to the right. Panics if index is out of bounds.
Sourcepub fn remove(&self, index: usize) -> V
pub fn remove(&self, index: usize) -> V
Removes and returns the element at index, shifting elements left. Panics if index is out of bounds.
Sourcepub fn swap_remove(&self, index: usize) -> V
pub fn swap_remove(&self, index: usize) -> V
Removes and returns the element at index by swapping in the last element.
O(1) removal when order does not matter.
Sourcepub fn contains(&self, value: &V) -> boolwhere
V: PartialEq,
pub fn contains(&self, value: &V) -> boolwhere
V: PartialEq,
Returns true if the ValueVec contains an element with the given value.
Sourcepub fn extend<I>(&self, iter: I)where
I: IntoIterator<Item = V>,
pub fn extend<I>(&self, iter: I)where
I: IntoIterator<Item = V>,
Extends the vector by moving in elements from an iterator.