pub trait List<'a, T: 'a> {
Show 15 methods
// Required methods
fn len(&self) -> usize;
fn head(&self) -> Option<&T>;
fn last(&self) -> Option<&T>;
fn iter(&self) -> impl Iterator<Item = &'a T>;
fn iter_mut(&mut self) -> impl Iterator<Item = &'a mut T>;
fn into_iter(self) -> impl Iterator<Item = T>;
fn push(&mut self, payload: T);
fn pop_back(&mut self) -> Option<T>;
fn pop_front(&mut self) -> Option<T>;
fn remove(&mut self, index: usize) -> Result<T>;
// Provided methods
fn is_empty(&self) -> bool { ... }
fn get(&self, index: usize) -> Result<&'a T> { ... }
fn get_mut(&mut self, index: usize) -> Result<&'a mut T> { ... }
fn clear(&mut self) { ... }
fn find(&self, value: &T) -> Option<usize>
where T: PartialEq<T> { ... }
}Expand description
This trait defines common API for all list implementations.
Required Methods§
Sourcefn iter(&self) -> impl Iterator<Item = &'a T>
fn iter(&self) -> impl Iterator<Item = &'a T>
Returns an iterator over the immutable items of the list.
Sourcefn iter_mut(&mut self) -> impl Iterator<Item = &'a mut T>
fn iter_mut(&mut self) -> impl Iterator<Item = &'a mut T>
Returns an iterator over the mutable items of the list.
Sourcefn pop_back(&mut self) -> Option<T>
fn pop_back(&mut self) -> Option<T>
Removes a node from the end of the list and returns its payload value.
Provided Methods§
Sourcefn get(&self, index: usize) -> Result<&'a T>
fn get(&self, index: usize) -> Result<&'a T>
Returns a list item by index, or error if index out of bounds.
Efficiency: O(n)
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.