[][src]Struct fwdlist::Cursor

pub struct Cursor<'a, T> { /* fields omitted */ }

A cursor to navigate the list and reshape it.

Conceptually, a cursor moves between nodes, think the cursor of your text editor.

Cursor by example

use fwdlist::List;

let mut q: List<_> = (0..5).collect();
let mut c = q.cursor();

So given the list [0,1,2,3,4], the cursor c, represented by | initially points to the first node:

 |0 1 2 3 4

After advancing the cursor once c.advance():

  0|1 2 3 4

And after Advancing the cursor 4 times c.nth(4):

  0 1 2 3 4|

Modifying the structure of the list

A cursor let you modify the list after its position (the tail). A cursor is really an abstraction of a mutable pointer to the next node of the list.

With a cursor, you can truncate the list, insert and removes nodes, etc.

Methods

impl<'a, T> Cursor<'a, T>[src]

pub fn value(&self) -> Option<&T>[src]

A read-only reference to the following node's value. Return None if the cursor is past the end of the list.

pub fn value_mut(&mut self) -> Option<&mut T>[src]

A mutable reference to the following node's value. Return None if the cursor is past the end of the list.

pub fn advance(&mut self) -> bool[src]

Move the cursor past the following node. Returns true on success, false if the cursor is already at the end of the list.

pub fn len(&self) -> usize[src]

The lengths of the tail. This is O(1).

pub fn is_empty(&self) -> bool[src]

This is O(1).

pub fn position(&self) -> usize[src]

The position from the beginning of the list.

pub fn checkpoint(&mut self) -> Cursor<T>[src]

Returns a copy of the cursor, freezing self while the copy is alive.

pub fn nth(&mut self, nth: usize) -> usize[src]

Move forward by nth nodes in O(min(nth, self.len)). Returns the number of nodes skipped, which could be less than nth if there is not enough remaining nodes.

pub fn last(&mut self) -> usize[src]

Move forward before the last node of the list in O(self.len - 1). Returns the number of nodes skipped, which could be less than nth if there is not enough remaining nodes.

pub fn end(&mut self) -> usize[src]

Move the cursor forward after the end of the list in O(self.len).

pub fn insert(&mut self, v: T) -> &mut T[src]

Create a new node containing the value v and insert it at the current location in O(1).

pub fn remove(&mut self) -> Option<T>[src]

Remove the following node and return the contained value in O(1). Return None if the cursor is past the end of the list.

pub fn truncate(&mut self) -> List<T>[src]

Truncate the list after the cursor, returning the tail in O(1).

pub fn splice(&mut self, other: &mut List<T>)[src]

Insert the list other after the cursor.

  • In O(other.len()) if self.len > 0
  • O(1) if self.len == 0

pub fn split(&mut self, after: usize) -> List<T>[src]

Split the list after nth and return the tail in O(min(at, self.len)). This is the same as:

This example is not tested
{
    let mut c = c.checkpoint();
    c.nth(after);
    c.truncate()
}

pub fn remove_n(&mut self, count: usize) -> List<T>[src]

Remove count nodes after the cursor in O(min(count, self.len)). Return the removed list.

Trait Implementations

impl<'a, T> Into<Cursor<'a, T>> for ListIterMut<'a, T>[src]

Convert the mutable iterator into a cursor unstable API.

impl<'a, T> IntoIterator for Cursor<'a, T>[src]

type Item = &'a mut Cursor<'a, T>

The type of the elements being iterated over.

type IntoIter = CursorIntoIter<'a, T>

Which kind of iterator are we turning this into?

impl<'c, 'l, T> IntoIterator for &'c mut Cursor<'l, T>[src]

type Item = &'c mut Cursor<'l, T>

The type of the elements being iterated over.

type IntoIter = CursorIterMut<'c, 'l, T>

Which kind of iterator are we turning this into?

Auto Trait Implementations

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

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

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.