[][src]Struct traversal::DftPost

pub struct DftPost<'a, T, F, I> where
    T: ?Sized,
    F: Fn(&'a T) -> I,
    I: Iterator<Item = &'a T>, 
{ /* fields omitted */ }

Depth-First Traversal in Post-Order.

Cycles

DftPost does not handle cycles. If any cycles are present, then DftPost will result in an infinite (never ending) Iterator.

Example

use traversal::DftPost;

struct Node(&'static str, &'static [Node]);

let tree = Node("G", &[
    Node("C", &[
        Node("A", &[]),
        Node("B", &[])
    ]),
    Node("F", &[
        Node("D", &[]),
        Node("E", &[])
    ]),
]);

// `&tree` represents the root `Node`.
// The `Fn(&Node) -> Iterator<Item = &Node>` returns
// an `Iterator` to get the child `Node`s.
let iter = DftPost::new(&tree, |node| node.1.iter());

// Map `Iterator<Item = &Node>` into `Iterator<Item = &str>`
let mut iter = iter.map(|(depth, node)| (depth, node.0));

assert_eq!(iter.next(), Some((2, "A")));
assert_eq!(iter.next(), Some((2, "B")));
assert_eq!(iter.next(), Some((1, "C")));
assert_eq!(iter.next(), Some((2, "D")));
assert_eq!(iter.next(), Some((2, "E")));
assert_eq!(iter.next(), Some((1, "F")));
assert_eq!(iter.next(), Some((0, "G")));
assert_eq!(iter.next(), None);

Methods

impl<'a, T, F, I> DftPost<'a, T, F, I> where
    T: ?Sized,
    F: Fn(&'a T) -> I,
    I: Iterator<Item = &'a T>, 
[src]

pub fn new(root: &'a T, children: F) -> Self[src]

Creates a DftPost, where root is the starting Node.

The children Fn is (lazily) called for each Node as needed, where the returned Iterator produces the child Nodes for the given Node.

See DftPost for more information.

"FnOnce"

The Fn is a FnOnce from the point-of-view of a Node, as children is at most called once for each individual Node.

FusedIterator

While DftPost does not require FusedIterator, it assumes that no Nodes are produced after a None.

Trait Implementations

impl<'a, T, F: Clone, I: Clone> Clone for DftPost<'a, T, F, I> where
    T: Clone + ?Sized,
    F: Fn(&'a T) -> I,
    I: Iterator<Item = &'a T>, 
[src]

impl<'a, T, F, I> FusedIterator for DftPost<'a, T, F, I> where
    T: ?Sized,
    F: Fn(&'a T) -> I,
    I: Iterator<Item = &'a T>, 
[src]

impl<'a, T, F, I> Iterator for DftPost<'a, T, F, I> where
    T: ?Sized,
    F: Fn(&'a T) -> I,
    I: Iterator<Item = &'a T>, 
[src]

type Item = (usize, &'a T)

The type of the elements being iterated over.

Auto Trait Implementations

impl<'a, T: ?Sized, F, I> RefUnwindSafe for DftPost<'a, T, F, I> where
    F: RefUnwindSafe,
    T: RefUnwindSafe

impl<'a, T: ?Sized, F, I> Send for DftPost<'a, T, F, I> where
    F: Send,
    T: Sync

impl<'a, T: ?Sized, F, I> Sync for DftPost<'a, T, F, I> where
    F: Sync,
    T: Sync

impl<'a, T: ?Sized, F, I> Unpin for DftPost<'a, T, F, I> where
    F: Unpin

impl<'a, T: ?Sized, F, I> UnwindSafe for DftPost<'a, T, F, I> where
    F: UnwindSafe,
    T: RefUnwindSafe

Blanket Implementations

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

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

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

impl<T> From<T> for T[src]

impl<T, U> Into<U> 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> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.