Trait DynamicArray

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

Source

fn with_capacity(capacity: usize) -> Self
where 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.

Source

fn capacity(&self) -> usize

Returns the capacity of the array.

Source

unsafe fn set_len(&mut self, len: usize)

Change the length of the array.

Provided Methods§

Source

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()).

Source

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.

Source

fn push(&mut self, value: T)

Appends the value to the array.

§Panics

If the array is full and cannot grow.

Source

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.

Source

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.

Source

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.

Implementors§

Source§

impl<T> DynamicArray<T> for VecArray<T>

Source§

impl<T, S, M, N> DynamicArray<T> for NestedArray<T, S, M, N>
where S: Split, M: DynamicArray<N>, N: DynamicArray<T> + Clone,

Source§

impl<T: Clone> DynamicArray<T> for RcArray<T>