Struct linked_list::Cursor
[−]
[src]
pub struct Cursor<'a, T: 'a> { /* fields omitted */ }
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 are 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 accomadate 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>
[src]
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>
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.