Struct Cursor

pub struct Cursor<'a, T: 'a, A: Allocator = Global> { pub(in ::collections::linked_list) index: usize, pub(in ::collections::linked_list) current: Option<NonNull<Node<T>>>, pub(in ::collections::linked_list) list: &'a LinkedList<T, A> }

A cursor over a LinkedList.

A Cursor is like an iterator, except that it can freely seek back-and-forth.

Cursors always rest between two elements in the list, and index in a logically circular way. To accommodate this, there is a "ghost" non-element that yields None between the head and tail of the list.

When created, cursors start at the front of the list, or the "ghost" non-element if the list is empty.

Fields

index: usize
current: Option<NonNull<Node<T>>>
list: &'a LinkedList<T, A>

Implementations

impl<'a, T, A: Allocator> Cursor<'a, T, A>

fn index(&self) -> Option<usize>

Returns the cursor position index within the LinkedList.

This returns None if the cursor is currently pointing to the "ghost" non-element.

fn move_next(&mut self)

Moves the cursor to the next element of the LinkedList.

If the cursor is pointing to the "ghost" non-element then this will move it to the first element of the LinkedList. If it is pointing to the last element of the LinkedList then this will move it to the "ghost" non-element.

fn move_prev(&mut self)

Moves the cursor to the previous element of the LinkedList.

If the cursor is pointing to the "ghost" non-element then this will move it to the last element of the LinkedList. If it is pointing to the first element of the LinkedList then this will move it to the "ghost" non-element.

fn current(&self) -> Option<&'a T>

Returns a reference to the element that the cursor is currently pointing to.

This returns None if the cursor is currently pointing to the "ghost" non-element.

fn peek_next(&self) -> Option<&'a T>

Returns a reference to the next element.

If the cursor is pointing to the "ghost" non-element then this returns the first element of the LinkedList. If it is pointing to the last element of the LinkedList then this returns None.

fn peek_prev(&self) -> Option<&'a T>

Returns a reference to the previous element.

If the cursor is pointing to the "ghost" non-element then this returns the last element of the LinkedList. If it is pointing to the first element of the LinkedList then this returns None.

fn front(&self) -> Option<&'a T>

Provides a reference to the front element of the cursor's parent list, or None if the list is empty.

fn back(&self) -> Option<&'a T>

Provides a reference to the back element of the cursor's parent list, or None if the list is empty.

fn as_list(&self) -> &'a LinkedList<T, A>

Provides a reference to the cursor's parent list.

Trait Implementations

impl<T, A: Allocator> Clone for Cursor<'_, T, A>

fn clone(&self) -> Self

impl<T: Debug, A: Allocator> Debug for Cursor<'_, T, A>

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl<T: Sync, A: Allocator + Sync> Send for Cursor<'_, T, A>

impl<T: Sync, A: Allocator + Sync> Sync for Cursor<'_, T, A>

Auto Trait Implementations

impl<'a, T, A> Freeze for Cursor<'a, T, A> where Option<NonNull<Node<T>>>: Freeze, &'a LinkedList<T, A>: Freeze,

impl<'a, T, A> RefUnwindSafe for Cursor<'a, T, A> where Option<NonNull<Node<T>>>: RefUnwindSafe, &'a LinkedList<T, A>: RefUnwindSafe,

impl<'a, T, A> Unpin for Cursor<'a, T, A> where Option<NonNull<Node<T>>>: Unpin, &'a LinkedList<T, A>: Unpin,

impl<'a, T, A> UnsafeUnpin for Cursor<'a, T, A> where Option<NonNull<Node<T>>>: UnsafeUnpin, &'a LinkedList<T, A>: UnsafeUnpin,

impl<'a, T, A> UnwindSafe for Cursor<'a, T, A> where Option<NonNull<Node<T>>>: UnwindSafe, &'a LinkedList<T, A>: UnwindSafe,

Blanket Implementations

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

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for Cursor<'a, T, A> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for Cursor<'a, T, A> where T: ?Sized,

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

impl<T> CloneToUninit for Cursor<'a, T, A> where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for Cursor<'a, T, A>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> SizeHint for Cursor<'a, T, A> where T: ?Sized,

fn lower_bound(&self) -> usize
fn upper_bound(&self) -> Option<usize>

impl<T> SizedTypeProperties for Cursor<'a, T, A>

impl<T> ToOwned for Cursor<'a, T, A> where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T, U> Into<U> for Cursor<'a, T, A> where U: From<T>,

fn into(self) -> U

Calls U::from(self).

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

impl<T, U> TryFrom<U> for Cursor<'a, T, A> where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for Cursor<'a, T, A> where U: TryFrom<T>,

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