pub struct Cursor<'a, T: 'a> { /* private fields */ }
Expand description
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.
Implementations§
Source§impl<'a, T> Cursor<'a, T>
impl<'a, T> Cursor<'a, T>
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Resets the cursor to lie between the first and last element in the list.
Sourcepub fn peek_next(&mut self) -> Option<&mut T>
pub fn peek_next(&mut self) -> Option<&mut T>
Gets the next element in the list, without moving the cursor head.
Sourcepub fn peek_prev(&mut self) -> Option<&mut T>
pub fn peek_prev(&mut self) -> Option<&mut T>
Gets the previous element in the list, without moving the cursor head.
Sourcepub fn insert(&mut self, elem: T)
pub 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
.
Sourcepub fn remove(&mut self) -> Option<T>
pub 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
pub fn split(&mut self) -> LinkedList<T>
Sourcepub fn splice(&mut self, other: &mut LinkedList<T>)
pub fn splice(&mut self, other: &mut LinkedList<T>)
Inserts the entire list’s contents right after the cursor.
Sourcepub fn seek_forward(&mut self, by: usize)
pub fn seek_forward(&mut self, by: usize)
Calls next
the specified number of times.
Sourcepub fn seek_backward(&mut self, by: usize)
pub fn seek_backward(&mut self, by: usize)
Calls prev
the specified number of times.