Struct fwdlist::Cursor [] [src]

pub struct Cursor<'a, T: 'a> { /* 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.next():

  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]

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

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

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

The lengths of the tail.

The position from the beginning of the list.

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

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.

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.

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

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

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

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

Insert the list other after the cursor.

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

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

{
    let mut c = c.checkpoint();
    c.nth(after);
    c.truncate()
}

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

Trait Implementations

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

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

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

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more