Skip to main content

List

Trait List 

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

Source

fn len(&self) -> usize

Returns list size.

Source

fn head(&self) -> Option<&T>

Returns the payload value of the first node in the list.

Source

fn last(&self) -> Option<&T>

Returns the payload value of the last node in the list.

Source

fn iter(&self) -> impl Iterator<Item = &'a T>

Returns an iterator over the immutable items of the list.

Source

fn iter_mut(&mut self) -> impl Iterator<Item = &'a mut T>

Returns an iterator over the mutable items of the list.

Source

fn into_iter(self) -> impl Iterator<Item = T>

Returns an iterator that consumes the list.

Source

fn push(&mut self, payload: T)

Adds a new node to the list.

Source

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

Removes a node from the end of the list and returns its payload value.

Source

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

Removes a node from the front of the list and returns its payload value.

Source

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

Removes a node from the specified location in the list.

Provided Methods§

Source

fn is_empty(&self) -> bool

Checks if the list is empty.

Efficiency: O(1)

Source

fn get(&self, index: usize) -> Result<&'a T>

Returns a list item by index, or error if index out of bounds.

Efficiency: O(n)

Source

fn get_mut(&mut self, index: usize) -> Result<&'a mut T>

Returns a mutable list item by index, or error if index out of bounds.

Efficiency: O(n)

Source

fn clear(&mut self)

Removes all items from the list.

Efficiency: O(n)

Source

fn find(&self, value: &T) -> Option<usize>
where T: PartialEq<T>,

Finds the first node whose payload is equal to the given value and returns its index. Returns None if there is no such node.

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.

Implementors§

Source§

impl<'a, T> List<'a, T> for SortedList<T>
where T: PartialOrd + 'a,

Source§

impl<'a, T: 'a> List<'a, T> for SinglyLinkedList<T>