Struct CursorMut

Source
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>

Source

pub fn is_some(&self) -> bool

Returns true if the cursor points to Some, indicating that the cursor is on a valid Node.

Source

pub fn is_none(&self) -> bool

Returns true if the cursor points to None, indicating that the cursor is on a ghost node.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source

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
                       ^
                    cursor

Postcondition:

    self.head -> A <-> B <-> C <- self.tail
                             ^
                          cursor
Source

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
                 ^
              cursor

Postcondition:

    self.head -> A <-> B <-> C <- self.tail
                 ^
              cursor
Source

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
                             ^
                          cursor

Postcondition:

    self.head -> A <-> B <-> D <- self.tail
                       ^
                    cursor
Source

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
                             ^
                          cursor

Postcondition:

    self.head -> C <-> D <- self.tail
                       ^
                     cursor

    return.head -> A <-> B <- return.tail
Source

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
                       ^
                     cursor

Postcondition:

    self.head -> A <-> B <- self.tail
                       ^
                     cursor

    return.head -> C <-> D <- return.tail
Source

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.tail

Postcondition:

    self.head -> A <-> 1 <-> 2 <-> B <-> C <- self.back
                                   ^
                                 cursor
Source

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.tail

Postcondition

    self.head -> A <-> B <-> 1 <-> 2 <-> C <- self.tail
                       ^
                    cursor

Auto Trait Implementations§

§

impl<'a, T> Freeze for CursorMut<'a, T>

§

impl<'a, T> RefUnwindSafe for CursorMut<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> !Send for CursorMut<'a, T>

§

impl<'a, T> !Sync for CursorMut<'a, T>

§

impl<'a, T> Unpin for CursorMut<'a, T>

§

impl<'a, T> !UnwindSafe for CursorMut<'a, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V