Vector

Trait Vector 

Source
pub trait Vector<T>:
    Deref<Target = [T]>
    + DerefMut
    + VectorView<T> {
Show 17 methods // Required methods fn capacity(&self) -> usize; fn len(&self) -> usize; // Provided methods fn as_mut_slice(&mut self) -> &mut [T] { ... } fn as_slice(&self) -> &[T] { ... } fn clear(&mut self) { ... } fn extend_from_slice( &mut self, other: &[T], ) -> Result<(), VectorModificationError> where T: Clone { ... } unsafe fn extend_from_slice_unchecked(&mut self, other: &[T]) where T: Clone { ... } fn insert( &mut self, index: usize, element: T, ) -> Result<(), VectorModificationError> { ... } fn is_empty(&self) -> bool { ... } fn is_full(&self) -> bool { ... } fn pop(&mut self) -> Option<T> { ... } fn push(&mut self, value: T) -> Result<(), VectorModificationError> { ... } unsafe fn push_unchecked(&mut self, value: T) { ... } fn remove(&mut self, index: usize) -> Option<T> { ... } fn resize( &mut self, new_len: usize, value: T, ) -> Result<(), VectorModificationError> where T: Clone { ... } fn resize_with<F: FnMut() -> T>( &mut self, new_len: usize, f: F, ) -> Result<(), VectorModificationError> { ... } fn truncate(&mut self, new_len: usize) { ... }
}
Expand description

Defines the interface of a vector.

Required Methods§

Source

fn capacity(&self) -> usize

Returns the capacity of the vector

Source

fn len(&self) -> usize

Returns the number of elements stored inside the vector

Provided Methods§

Source

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

Returns a mutable slice to the contents of the vector

Source

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

Returns a slice to the contents of the vector

Source

fn clear(&mut self)

Removes all elements from the vector

Source

fn extend_from_slice( &mut self, other: &[T], ) -> Result<(), VectorModificationError>
where T: Clone,

Append all elements from other via Clone.

Source

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

Append all elements from other via Clone.

§Safety
Source

fn insert( &mut self, index: usize, element: T, ) -> Result<(), VectorModificationError>

Inserts an element at the provided index and shifting all elements after the index to the right.

Source

fn is_empty(&self) -> bool

Returns true if the vector is empty, otherwise false

Source

fn is_full(&self) -> bool

Returns true if the vector is full, otherwise false

Source

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

Removes the last element of the vector and returns it to the user. If the vector is empty it returns None.

Source

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

Adds an element at the end of the vector. If the vector is full and the element cannot be added it returns VectorModificationError::InsertWouldExceedCapacity.

Source

unsafe fn push_unchecked(&mut self, value: T)

Adds an element at the end of the vector.

§Safety
Source

fn remove(&mut self, index: usize) -> Option<T>

Removes the element at the provided index and returns it.

Source

fn resize( &mut self, new_len: usize, value: T, ) -> Result<(), VectorModificationError>
where T: Clone,

Fill the remaining space of the vector with value.

Source

fn resize_with<F: FnMut() -> T>( &mut self, new_len: usize, f: F, ) -> Result<(), VectorModificationError>

Fill the remaining space of the vector with value.

Source

fn truncate(&mut self, new_len: usize)

Truncates the vector to len and drops all elements right of len in reverse order.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T> Vector<T> for RelocatableVec<T>

Source§

impl<T, Allocator: BaseAllocator> Vector<T> for PolymorphicVec<'_, T, Allocator>

Source§

impl<T, const CAPACITY: usize> Vector<T> for StaticVec<T, CAPACITY>