pub struct DoublyLinkedList<T> { /* private fields */ }
Expand description

A two-directional linked list, known more commonly as a DoublyLinkedList.

Implementations

Constructs a new, empty, DoublyLinkedList.

Returns the len or the number of Nodes within the DoublyLinkedList.

Example
let list = dl_list![1, 2, 3];
 
assert_eq!(list.len(), 3);

Returns a bool that determines if the list is empty.

Example
let mut list = DoublyLinkedList::<i32>::new();
 
assert_eq!(list.is_empty(), true);
 
list.push_back(1);
assert_eq!(list.is_empty(), false);

Clears the DoublyLinkedList settings its fields back to their default values.

Example
let mut list = dl_list![1, 2, 3, 4, 5];
list.clear();
 
assert_eq!(list, DoublyLinkedList::<i32>::new());

Returns a reference to the Node at the front of the DoublyLinkedList, also known as the head. Time complexity is O(1).

Example
let list = dl_list![2, 4, 0];
 
assert_eq!(list.front(), Some(&2));

Returns a reference to the Node at the back of the DoublyLinkedList, also known as the tail. Time complexity is O(1).

Example
let list = dl_list![2, 4, 0];
 
assert_eq!(list.back(), Some(&0));

Returns a mutable reference to the Node at the front of the DoublyLinkedList, also known as the head. Time complexity is O(1).

Example
let mut list = dl_list![2, 4, 0];
 
assert_eq!(list.front_mut(), Some(&mut 2));

Returns a mutable reference to the Node at the back of the DoublyLinkedList, also known as the tail. Time complexity is O(1).

Example
let mut list = dl_list![2, 4, 0];
 
assert_eq!(list.back_mut(), Some(&mut 0));

Pushes or prepends a new Node to the front of the DoublyLinkedList. Time complexity is O(1).

Example
let mut list = DoublyLinkedList::new();
 
list.push_front(1);
list.push_front(2);
list.push_front(3);
 
assert_eq!(list, dl_list![3, 2, 1]);

Pushes or appends a new Node to the back of the DoublyLinkedList. Time complexity is O(1).

Example
let mut list = DoublyLinkedList::new();
 
list.push_back(1);
list.push_back(2);
list.push_back(3);
 
assert_eq!(list, dl_list![1, 2, 3]);

Returns a reference to the Node at the given index. Time complexity is O(n).

Example
let list = dl_list![1, 2, 3];
 
assert_eq!(list.get(1), Some(&2));

Returns a mutable reference to the Node at the given index. Time complexity is O(n).

Example
let mut list = dl_list![1, 2, 3];
 
assert_eq!(list.get_mut(1), Some(&mut 2));

Removes the list’s head Node, returning its value. Time complexity is O(1).

Example
let mut list = dl_list![1, 2, 3];
let pop = list.pop_front();
 
assert_eq!(pop, Some(1));
assert_eq!(list, dl_list![2, 3]);

Removes the list’s tail Node, returning its value. Time complexity is O(1).

Example
let mut list = dl_list![1, 2, 3];
let pop = list.pop_back();
 
assert_eq!(pop, Some(3));
assert_eq!(list, dl_list![1, 2]);

Removes the list’s head Node. Time complexity is O(1).

Example
let mut list = dl_list![1, 2, 3];
list.remove_front();
 
assert_eq!(list, dl_list![2, 3]);

Removes the list’s tail Node. Time complexity is O(1).

Example
let mut list = dl_list![1, 2, 3];
list.remove_back();
 
assert_eq!(list, dl_list![1, 2]);

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Creates a value from an iterator. Read more

The returned type after indexing.

Performs the indexing (container[index]) operation. Read more

Performs the mutable indexing (container[index]) operation. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.