pub trait DynamicArray<T>: Array<T> {
// Required methods
fn with_capacity(capacity: usize) -> Self
where Self: Sized;
fn capacity(&self) -> usize;
unsafe fn set_len(&mut self, len: usize);
// Provided methods
fn reserve(&mut self, additional: usize) { ... }
unsafe fn push_unchecked(&mut self, value: T) { ... }
fn push(&mut self, value: T) { ... }
fn extend<I>(&mut self, iter: I)
where Self: Sized,
I: IntoIterator<Item = T> { ... }
fn extend_from_slice(&mut self, other: &[T])
where T: Clone { ... }
fn extend_with_element(&mut self, value: T, n: usize)
where T: Clone { ... }
}Expand description
A simple trait for a dynamic array like struct.
Required Methods§
Sourcefn with_capacity(capacity: usize) -> Selfwhere
Self: Sized,
fn with_capacity(capacity: usize) -> Selfwhere
Self: Sized,
Creates a array with the specified capacity.
The implementation is free to choose if the array can grow beyond this capacity or not.
Provided Methods§
Sourcefn reserve(&mut self, additional: usize)
fn reserve(&mut self, additional: usize)
Reserve capacity for at least additional more elements.
§Panics
If the array cannot satisfy the request.
The default implementation panics if additional > (self.capacity() - self.len()).
Sourceunsafe fn push_unchecked(&mut self, value: T)
unsafe fn push_unchecked(&mut self, value: T)
Write value to the end of the array and increment the length.
This method is used in the default implementation of push, extend_with_element and
extend_from_slice.
§Safety
It’s unsafe because the capacity is not checked.
Sourcefn extend<I>(&mut self, iter: I)where
Self: Sized,
I: IntoIterator<Item = T>,
fn extend<I>(&mut self, iter: I)where
Self: Sized,
I: IntoIterator<Item = T>,
Appends all elements of iter to the array.
§Panics
If the array cannot grow to accommodate all elements.
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 in a slice to the array.
§Panics
If the array cannot grow to accommodate all elements.
Sourcefn extend_with_element(&mut self, value: T, n: usize)where
T: Clone,
fn extend_with_element(&mut self, value: T, n: usize)where
T: Clone,
Extend the array by n additional clones of value.
§Panics
If the array cannot grow to accommodate all elements.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".