Trait charcoal::traversal::Traversable[][src]

pub trait Traversable: Sized {
    type Leaf;
    type Branch;
    type Cursor: Clone + Debug + Eq;
    fn advance_cursor<V>(
        &self,
        cursor: Self::Cursor,
        direction: VisitorDirection<Self::Cursor, V>
    ) -> CursorResult<Self::Cursor>;
fn cursor_to_root(&self) -> Self::Cursor;
fn value_of(
        &self,
        cursor: &Self::Cursor
    ) -> NodeValue<&Self::Branch, &Self::Leaf>;
fn parent_of(&self, cursor: &Self::Cursor) -> Option<Self::Cursor>;
fn num_children_of(&self, cursor: &Self::Cursor) -> usize;
fn nth_child_of(
        &self,
        cursor: &Self::Cursor,
        child_num: usize
    ) -> Option<Self::Cursor>; fn step<V>(
        &self,
        visitor: V,
        cursor: CursorResult<Self::Cursor>
    ) -> Step<Self::Cursor, V::Output>
    where
        V: Visitor,
        &'a Self: Borrow<V::Target>,
        Self::Cursor: From<<V::Target as Traversable>::Cursor> + Into<<V::Target as Traversable>::Cursor>
, { ... }
fn traverse<V>(&self, visitor: V) -> V::Output
    where
        V: Visitor,
        &'a Self: Borrow<V::Target>,
        Self::Cursor: From<<V::Target as Traversable>::Cursor> + Into<<V::Target as Traversable>::Cursor>
, { ... }
fn traverse_from<V>(
        &self,
        starting_cursor: Self::Cursor,
        visitor: V
    ) -> V::Output
    where
        V: Visitor,
        &'a Self: Borrow<V::Target>,
        Self::Cursor: From<<V::Target as Traversable>::Cursor> + Into<<V::Target as Traversable>::Cursor>
, { ... } }

Data structures which can be traversed using Visitors.

Associated Types

type Leaf[src]

The payload of the node if it’s a leaf node.

type Branch[src]

The payload of the node if it’s a branch node.

type Cursor: Clone + Debug + Eq[src]

The type for the cursor which will be used for keeping track of the traversed nodes.

Must be very cheaply clonable, but not required to be Copy. Cursors are not guaranteed to be stable — relying on their stability for memory safety might cause undefined behavior. The only case in which those keys should actually be stored for extended periods of time is when a visitor needs to remember node locations, since it’s a logic error to interleave step/step_mut calls for read-only and mutating visitors or for multiple mutating visitors; still, visitors should check for key error conditions and panic if those happen.

Loading content...

Required methods

fn advance_cursor<V>(
    &self,
    cursor: Self::Cursor,
    direction: VisitorDirection<Self::Cursor, V>
) -> CursorResult<Self::Cursor>
[src]

Advances the specified cursor according to the specified directions from the visitor.

Panics

Required to panic if the current cursor value is invalid, i.e. it’s impossible to determine the previously valid cursor value (as opposed to merely invalid directions but valid cursor, which can be recovered from).

fn cursor_to_root(&self) -> Self::Cursor[src]

Returns the cursor pointing to the root node.

fn value_of(
    &self,
    cursor: &Self::Cursor
) -> NodeValue<&Self::Branch, &Self::Leaf>
[src]

Returns a by-reference NodeValue of the node at the specified cursor.

Panics

Required to panic if the cursor value is invalid.

fn parent_of(&self, cursor: &Self::Cursor) -> Option<Self::Cursor>[src]

Returns a cursor to the parent of the node at the specified cursor, or None if that node is the root node.

Panics

Required to panic if the cursor value is invalid. If the cursor is valid but has no parent, the method must return None instead of panicking.

fn num_children_of(&self, cursor: &Self::Cursor) -> usize[src]

Returns the number of children of the node at the specified cursor.

Panics

Required to panic if the cursor value is invalid.

fn nth_child_of(
    &self,
    cursor: &Self::Cursor,
    child_num: usize
) -> Option<Self::Cursor>
[src]

Returns a cursor to the *n*th child of the node at the specified cursor, or None if the child at that index does not exist.

Panics

Required to panic if cursor value is invalid.

Loading content...

Provided methods

fn step<V>(
    &self,
    visitor: V,
    cursor: CursorResult<Self::Cursor>
) -> Step<Self::Cursor, V::Output> where
    V: Visitor,
    &'a Self: Borrow<V::Target>,
    Self::Cursor: From<<V::Target as Traversable>::Cursor> + Into<<V::Target as Traversable>::Cursor>, 
[src]

Performs one step of the visitor from the specified cursor, returning either the cursor for the next step or the final result of the visitor if it ended.

It’s a logic error to interleave calls to step through a Visitor with equivalent calls for one or more VisitorMut on the same traversable. This cannot invoke undefined behavior, but may produce unexpected results, such as infinite loops or panicking.

Panics

The visitor itself may panic, but otherwise the method should not add any panics on its own.

fn traverse<V>(&self, visitor: V) -> V::Output where
    V: Visitor,
    &'a Self: Borrow<V::Target>,
    Self::Cursor: From<<V::Target as Traversable>::Cursor> + Into<<V::Target as Traversable>::Cursor>, 
[src]

Traverses the traversable from the root node until the end, returning the final result of the visitor.

fn traverse_from<V>(
    &self,
    starting_cursor: Self::Cursor,
    visitor: V
) -> V::Output where
    V: Visitor,
    &'a Self: Borrow<V::Target>,
    Self::Cursor: From<<V::Target as Traversable>::Cursor> + Into<<V::Target as Traversable>::Cursor>, 
[src]

Traverses the traversable from the specified starting point until the end, returning the final result of the visitor.

Loading content...

Implementations on Foreign Types

impl<T: Traversable> Traversable for &T[src]

type Leaf = T::Leaf

type Branch = T::Branch

type Cursor = T::Cursor

impl<T: Traversable> Traversable for &mut T[src]

type Leaf = T::Leaf

type Branch = T::Branch

type Cursor = T::Cursor

Loading content...

Implementors

impl<B, L, K, S> Traversable for BinaryTree<B, L, K, S> where
    S: Storage<Element = Node<B, L, K>, Key = K>,
    K: Clone + Debug + Eq
[src]

This is supported on crate feature binary_tree only.

type Branch = B

type Leaf = L

type Cursor = K

impl<B, L, K, S> Traversable for FreeformTree<B, L, K, S> where
    S: Storage<Element = Node<B, L, K>, Key = K>,
    K: Clone + Debug + Eq
[src]

This is supported on crate feature freeform_tree only.

type Leaf = L

type Branch = B

type Cursor = K

impl<B, L, K, S> Traversable for Octree<B, L, K, S> where
    S: Storage<Element = Node<B, L, K>, Key = K>,
    K: Clone + Debug + Eq
[src]

This is supported on crate feature octree only.

type Leaf = L

type Branch = B

type Cursor = K

impl<B, L, K, S> Traversable for Quadtree<B, L, K, S> where
    S: Storage<Element = Node<B, L, K>, Key = K>,
    K: Clone + Debug + Eq
[src]

This is supported on crate feature quadtree only.

type Leaf = L

type Branch = B

type Cursor = K

Loading content...