pub trait Vec<T>: RawVec<T> + AllocatorAware<T> {
Show 31 methods
// Provided methods
fn is_empty(&self) -> bool { ... }
fn as_non_null(&self) -> NonNull<T> { ... }
fn as_slice(&self) -> &[T] { ... }
fn as_mut_slice(&mut self) -> &mut [T] { ... }
fn as_buf(&self) -> NonNull<[T]> { ... }
fn reserve(&mut self, additional: usize) { ... }
fn try_reserve(&mut self, additional: usize) -> Result<(), AllocError> { ... }
fn reserve_exact(&mut self, additional: usize) { ... }
fn try_reserve_exact(&mut self, additional: usize) -> Result<(), AllocError> { ... }
fn shrink_to_fit(&mut self) { ... }
fn shrink_to(&mut self, min_capacity: usize) { ... }
fn push(&mut self, value: T) { ... }
fn push_within_capacity(&mut self, value: T) -> Result<(), T> { ... }
fn pop(&mut self) -> Option<T> { ... }
fn insert(&mut self, index: usize, element: T) { ... }
fn remove(&mut self, index: usize) -> T { ... }
fn swap_remove(&mut self, index: usize) -> T { ... }
fn append(&mut self, other: &mut dyn Vec<T, Alloc = Self::Alloc>) { ... }
fn clear(&mut self) { ... }
fn resize(&mut self, new_len: usize, value: T)
where T: Clone { ... }
fn resize_with(&mut self, new_len: usize, f: &mut dyn FnMut() -> T) { ... }
fn truncate(&mut self, new_len: usize) { ... }
fn replace_from_slice(&mut self, other: &[T])
where T: Clone { ... }
fn extend_from_slice(&mut self, other: &[T])
where T: Clone { ... }
fn extend_with(&mut self, n: usize, value: T)
where T: Clone { ... }
fn extend(&mut self, iter: &mut dyn OutIterator<Item = T>) { ... }
fn extend_exact(&mut self, iter: &mut dyn ExactSizeOutIterator<Item = T>) { ... }
fn iter(&self) -> Iter<'_, T> { ... }
fn iter_mut(&mut self) -> IterMut<'_, T> { ... }
fn give(&mut self, other: &mut dyn Vec<T, Alloc = Self::Alloc>) { ... }
fn swap(&mut self, other: &mut dyn Vec<T, Alloc = Self::Alloc>) { ... }
}
Expand description
High level dyn-dispatchable Vec
.
Provided Methods§
Sourcefn as_non_null(&self) -> NonNull<T>
fn as_non_null(&self) -> NonNull<T>
Returns a NonNull<T>
pointer to the underlying storage.
If RawVec::as_ptr
returns null, it returns NonNull::dangling
suitable for zero-sized reads.
Sourcefn as_mut_slice(&mut self) -> &mut [T]
fn as_mut_slice(&mut self) -> &mut [T]
Returns the underlying storage as a mutable slice of elements.
Sourcefn as_buf(&self) -> NonNull<[T]>
fn as_buf(&self) -> NonNull<[T]>
Returns a pointer to the underlying storage as a NonNull
slice.
Sourcefn reserve(&mut self, additional: usize)
fn reserve(&mut self, additional: usize)
Reserve extra capacity for at least additional
elements.
May reserve more space than requested to avoid future reallocations. Does nothing if the capacity is already sufficient.
§Panics
If capacity exceeds RawVec::max_len
or on allocation failure.
Sourcefn try_reserve(&mut self, additional: usize) -> Result<(), AllocError>
fn try_reserve(&mut self, additional: usize) -> Result<(), AllocError>
Reserve extra capacity for at least additional
elements.
May reserve more space than requested to avoid future reallocations. Does nothing if the capacity is already sufficient.
§Errors
If capacity exceeds RawVec::max_len
or on allocation failure.
Sourcefn reserve_exact(&mut self, additional: usize)
fn reserve_exact(&mut self, additional: usize)
Reserve extra capacity for additional
elements.
Does nothing if the capacity is already sufficient.
§Panics
If capacity exceeds RawVec::max_len
or on allocation failure.
Sourcefn try_reserve_exact(&mut self, additional: usize) -> Result<(), AllocError>
fn try_reserve_exact(&mut self, additional: usize) -> Result<(), AllocError>
Reserve extra capacity for additional
elements.
Does nothing if the capacity is already sufficient.
§Errors
If capacity exceeds RawVec::max_len
or on allocation failure.
Sourcefn shrink_to_fit(&mut self)
fn shrink_to_fit(&mut self)
Sourcefn push_within_capacity(&mut self, value: T) -> Result<(), T>
fn push_within_capacity(&mut self, value: T) -> Result<(), T>
Sourcefn pop(&mut self) -> Option<T>
fn pop(&mut self) -> Option<T>
Removes the last element and returns it, or None
if it is empty.
Sourcefn insert(&mut self, index: usize, element: T)
fn insert(&mut self, index: usize, element: T)
Inserts element
at index
(<= len) in the vector.
§Panics
If index is greater than length, if capacity exceeds RawVec::max_len
or on allocation failure.
Sourcefn remove(&mut self, index: usize) -> T
fn remove(&mut self, index: usize) -> T
Removes element
at index
(< len) in the vector.
§Panics
If index is greater or equal to length, if capacity exceeds RawVec::max_len
or on allocation failure.
Sourcefn swap_remove(&mut self, index: usize) -> T
fn swap_remove(&mut self, index: usize) -> T
Removes element
at index
(< len) in the vector via “swap + pop”.
§Panics
If index is greater or equal to length, if capacity exceeds RawVec::max_len
or on allocation failure.
Sourcefn append(&mut self, other: &mut dyn Vec<T, Alloc = Self::Alloc>)
fn append(&mut self, other: &mut dyn Vec<T, Alloc = Self::Alloc>)
Appends all elements from other
to self
, removing them from other
.
§Panics
If capacity exceeds RawVec::max_len
or on allocation failure.
Sourcefn resize(&mut self, new_len: usize, value: T)where
T: Clone,
fn resize(&mut self, new_len: usize, value: T)where
T: Clone,
Resizes the vector, either cloning value
or truncating it.
§Panics
If capacity exceeds RawVec::max_len
or on allocation failure.
Sourcefn resize_with(&mut self, new_len: usize, f: &mut dyn FnMut() -> T)
fn resize_with(&mut self, new_len: usize, f: &mut dyn FnMut() -> T)
Resizes the vector, either appending the result of calling f
or truncating it.
§Panics
If capacity exceeds RawVec::max_len
or on allocation failure.
Sourcefn truncate(&mut self, new_len: usize)
fn truncate(&mut self, new_len: usize)
Resizes the vector, truncating it without affecting capacity.
Sourcefn replace_from_slice(&mut self, other: &[T])where
T: Clone,
fn replace_from_slice(&mut self, other: &[T])where
T: Clone,
Sourcefn extend_from_slice(&mut self, other: &[T])where
T: Clone,
fn extend_from_slice(&mut self, other: &[T])where
T: Clone,
Appends all elements from other
to self
by cloning them.
§Panics
If capacity exceeds RawVec::max_len
or on allocation failure.
Sourcefn extend_with(&mut self, n: usize, value: T)where
T: Clone,
fn extend_with(&mut self, n: usize, value: T)where
T: Clone,
Appends all n
copies of value
to self
.
§Panics
If capacity exceeds RawVec::max_len
or on allocation failure.
Sourcefn extend(&mut self, iter: &mut dyn OutIterator<Item = T>)
fn extend(&mut self, iter: &mut dyn OutIterator<Item = T>)
Appends the contents of iter
to self
.
§Panics
If capacity exceeds RawVec::max_len
or on allocation failure.
Sourcefn extend_exact(&mut self, iter: &mut dyn ExactSizeOutIterator<Item = T>)
fn extend_exact(&mut self, iter: &mut dyn ExactSizeOutIterator<Item = T>)
Appends the contents of iter
to self
.
More efficient specialization for when the iterator satisfies ExactSizeIterator
.
§Panics
If capacity exceeds RawVec::max_len
or on allocation failure.
Sourcefn iter_mut(&mut self) -> IterMut<'_, T>
fn iter_mut(&mut self) -> IterMut<'_, T>
Returns a mutable slice iterator for the underlying storage.