Trait Vec

Source
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§

Source

fn is_empty(&self) -> bool

Returns whether the vector contains elements.

Source

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.

Source

fn as_slice(&self) -> &[T]

Returns the underlying storage as a slice of elements.

Source

fn as_mut_slice(&mut self) -> &mut [T]

Returns the underlying storage as a mutable slice of elements.

Source

fn as_buf(&self) -> NonNull<[T]>

Returns a pointer to the underlying storage as a NonNull slice.

Source

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.

Source

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.

Source

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.

Source

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.

Source

fn shrink_to_fit(&mut self)

Tries to reallocate to shrink capacity as much as possible.

§Panics

On allocation failure.

Source

fn shrink_to(&mut self, min_capacity: usize)

Tries to reallocate to up to min_capacity.

§Panics

On allocation failure.

Source

fn push(&mut self, value: T)

Appends value.

§Panics

If capacity exceeds RawVec::max_len or on allocation failure.

Source

fn push_within_capacity(&mut self, value: T) -> Result<(), T>

Appends value within free capacity. Does not panic.

§Errors

If there is no free capacity.

Source

fn pop(&mut self) -> Option<T>

Removes the last element and returns it, or None if it is empty.

Source

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.

Source

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.

Source

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.

Source

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.

Source

fn clear(&mut self)

Removes and drops all elements from self without affecting capacity.

Source

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.

Source

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.

Source

fn truncate(&mut self, new_len: usize)

Resizes the vector, truncating it without affecting capacity.

Source

fn replace_from_slice(&mut self, other: &[T])
where T: Clone,

Replaces the contents of self with elements cloned from other.

§Panics

On allocation failure.

Source

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.

Source

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.

Source

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.

Source

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.

Source

fn iter(&self) -> Iter<'_, T>

Returns a slice iterator for the underlying storage.

Source

fn iter_mut(&mut self) -> IterMut<'_, T>

Returns a mutable slice iterator for the underlying storage.

Source

fn give(&mut self, other: &mut dyn Vec<T, Alloc = Self::Alloc>)

Replaces the contents of out with the contents of self, as if assigning the return value of take.

§Panics

On allocation failure.

Source

fn swap(&mut self, other: &mut dyn Vec<T, Alloc = Self::Alloc>)

Swaps the contents of other with the contents of self.

Implementors§

Source§

impl<T, V> Vec<T> for V
where V: RawVec<T> + AllocatorAware<T>,