Struct linked_list::Cursor [] [src]

pub struct Cursor<'a, T: 'a> {
    // some fields omitted
}

A cursor over a LinkedList.

A Cursor is like an iterator, except that it can freely seek back-and-forth, and can safely mutate the list during iteration. This is because the lifetime of its yielded references is tied to its own lifetime, instead of just the underlying list. This means cursors cannot yield multiple elements at once.

Cursors always rest between two elements in the list, and index in a logically circular way. To accommodate this, there is a "ghost" non-element that yields None between the head and tail of the list.

When created, cursors start between the ghost and the front of the list. That is, next will yield the front of the list, and prev will yield None. Calling prev again will yield the tail.

Methods

impl<'a, T> Cursor<'a, T>

fn reset(&mut self)

Resets the cursor to lie between the first and last element in the list.

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

Gets the next element in the list.

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

Gets the previous element in the list.

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

Gets the next element in the list, without moving the cursor head.

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

Gets the previous element in the list, without moving the cursor head.

fn insert(&mut self, elem: T)

Inserts an element at the cursor's location in the list, and moves the cursor head to lie before it. Therefore, the new element will be yielded by the next call to next.

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

Removes the next element in the list, without moving the cursor. Returns None if the list is empty, or if next is the ghost element

fn split(&mut self) -> LinkedList<T>

Splits the list into two at the cursor's current position. This will return a new list consisting of everything after the cursor, with the original list retaining everything before. The cursor will then lie between the tail and the ghost.

fn splice(&mut self, other: &mut LinkedList<T>)

Inserts the entire list's contents right after the cursor.

fn seek_forward(&mut self, by: usize)

Calls next the specified number of times.

fn seek_backward(&mut self, by: usize)

Calls prev the specified number of times.

Trait Implementations

impl<'a, T: Send> Send for Cursor<'a, T>

impl<'a, T: Sync> Sync for Cursor<'a, T>