linked_list

Struct Cursor

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

Source

pub fn reset(&mut self)

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

Source

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

Gets the next element in the list.

Source

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

Gets the previous element in the list.

Source

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

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

Source

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

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

Source

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.

Source

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

Source

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

Source

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

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

Source

pub fn seek_forward(&mut self, by: usize)

Calls next the specified number of times.

Source

pub fn seek_backward(&mut self, by: usize)

Calls prev the specified number of times.

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<'a, T> !UnwindSafe for Cursor<'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.