pub struct CursorMut<'a, T> { /* private fields */ }Expand description
§About
Its the great cursor, Charlie Brown!
See the module-level documentation for more information.
Implementations§
Source§impl<T> CursorMut<'_, T>
impl<T> CursorMut<'_, T>
Sourcepub fn is_some(&self) -> bool
pub fn is_some(&self) -> bool
Returns true if the cursor points to Some, indicating that the cursor
is on a valid Node.
Sourcepub fn is_none(&self) -> bool
pub fn is_none(&self) -> bool
Returns true if the cursor points to None, indicating that the cursor
is on a ghost node.
Sourcepub fn move_next(&mut self)
pub fn move_next(&mut self)
Advances the cursor to the next node in the list, moving from head to tail. If the cursor is at the ghost (pre-head) position and the list is non-empty, it moves to the head. The function is a no-op if the cursor is already at the tail or the list is empty.
Sourcepub fn move_prev(&mut self)
pub fn move_prev(&mut self)
Advances the cursor to the previous node in the list, moving from head to tail. The function is a no-op if the cursor is already at the head or the list is empty.
Sourcepub fn current(&mut self) -> Option<&mut T>
pub fn current(&mut self) -> Option<&mut T>
Returns a mutable reference to the data at the current position. It is necessary to return a mutable reference to retain the elision rule checks.
Sourcepub fn peek_next(&mut self) -> Option<&mut T>
pub fn peek_next(&mut self) -> Option<&mut T>
Returns a mutable reference to the data at the next node’s position. It’s necessary to return a mutable reference to retain the elision rule checks.
Sourcepub fn peek_prev(&mut self) -> Option<&mut T>
pub fn peek_prev(&mut self) -> Option<&mut T>
Returns a mutable reference to the data at the previous node’s position; It is necessary to return a mutable reference to retain the elision rule checks
Sourcepub fn insert_before(&mut self, element: T)
pub fn insert_before(&mut self, element: T)
Inserts a node before the cursor;
-
If the cursor is on the ghost node of an empty list, the new node becomes the new head and tail;
-
If the cursor is on the ghost node of a non-empty list, the new node becomes the new tail;
-
If the cursor is on the head, the new node is the new head;
Precondition:
self.head -> A <-> C <- self.tail
^
cursorPostcondition:
self.head -> A <-> B <-> C <- self.tail
^
cursorSourcepub fn insert_after(&mut self, element: T)
pub fn insert_after(&mut self, element: T)
Inserts a node after the cursor;
-
If the cursor is on the ghost node of an empty list, the new node becomes the new head and tail;
-
If the cursor is on the ghost node of a non-empty list, the new node becomes the new head;
-
If the cursor is on the tail, the new node is the new tail;
Precondition:
self.head -> A <-> C <- self.tail
^
cursorPostcondition:
self.head -> A <-> B <-> C <- self.tail
^
cursorSourcepub fn remove_current(&mut self) -> Option<T>
pub fn remove_current(&mut self) -> Option<T>
Removes and returns the data under the cursor’s current position and moves the cursor back one position
Precondition:
self.head -> A <-> B <-> C <-> D <- self.tail
^
cursorPostcondition:
self.head -> A <-> B <-> D <- self.tail
^
cursorSourcepub fn split_before(&mut self) -> LinkedList<T>
pub fn split_before(&mut self) -> LinkedList<T>
Returns a new list containing all nodes before the cursor,
modifying self to become all nodes after (and including) the cursor.
Precondition:
self.head -> A <-> B <-> C <-> D <- self.tail
^
cursorPostcondition:
self.head -> C <-> D <- self.tail
^
cursor
return.head -> A <-> B <- return.tailSourcepub fn split_after(&mut self) -> LinkedList<T>
pub fn split_after(&mut self) -> LinkedList<T>
Returns a new list that includes all nodes after the cursor, modifying self to become all nodes before (and including) the cursor
Precondition:
self.head -> A <-> B <-> C <-> D <- self.tail
^
cursorPostcondition:
self.head -> A <-> B <- self.tail
^
cursor
return.head -> C <-> D <- return.tailSourcepub fn splice_before(&mut self, input: LinkedList<T>)
pub fn splice_before(&mut self, input: LinkedList<T>)
Splices in a new list between the cursor node and the previous node
Precondition:
self.head -> A <-> B <-> C <- self.tail
^
cursor
input.head -> 1 <-> 2 <- input.tailPostcondition:
self.head -> A <-> 1 <-> 2 <-> B <-> C <- self.back
^
cursorSourcepub fn splice_after(&mut self, input: LinkedList<T>)
pub fn splice_after(&mut self, input: LinkedList<T>)
Splices in a new list between the cursor node and the next node
Precondition
self.head -> A <-> B <-> C <- self.tail
^
cursor
input.head -> 1 <-> 2 <- input.tailPostcondition
self.head -> A <-> B <-> 1 <-> 2 <-> C <- self.tail
^
cursor