Trait fera_array::DynamicArray
source · pub trait DynamicArray<T>: Array<T> {
fn with_capacity(capacity: usize) -> Self
where
Self: Sized;
fn capacity(&self) -> usize;
unsafe fn set_len(&mut self, len: usize);
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.