Visitor

Trait Visitor 

Source
pub trait Visitor: Sized {
    type Item;

    // Required method
    fn next(self) -> (Self::Item, Option<[Self; 2]>);

    // Provided methods
    fn level_remaining_hint(&self) -> (usize, Option<usize>) { ... }
    fn with_depth(self, start_depth: Depth) -> LevelIter<Self> { ... }
    fn zip<F: Visitor>(self, f: F) -> Zip<Self, F> { ... }
    fn map<B, F: Fn(Self::Item) -> B>(self, func: F) -> Map<Self, F> { ... }
    fn take(self, num: usize) -> Take<Self> { ... }
    fn flip(self) -> Flip<Self> { ... }
    fn dfs_preorder_iter(self) -> DfsPreOrderIter<Self>  { ... }
    fn dfs_inorder_iter(self) -> DfsInOrderIter<Self>  { ... }
    fn dfs_preorder(self, func: impl FnMut(Self::Item)) { ... }
    fn dfs_inorder(self, func: impl FnMut(Self::Item)) { ... }
    fn dfs_postorder(self, func: impl FnMut(Self::Item)) { ... }
}
Expand description

The trait this crate revoles around. A complete binary tree visitor.

Required Associated Types§

Source

type Item

The common item produced for both leafs and non leafs.

Required Methods§

Source

fn next(self) -> (Self::Item, Option<[Self; 2]>)

Consume this visitor, and produce the element it was pointing to along with it’s children visitors.

Provided Methods§

Source

fn level_remaining_hint(&self) -> (usize, Option<usize>)

Return the levels remaining including the one that will be produced by consuming this iterator. So if you first made this object from the root for a tree of size 5, it should return 5. Think of is as height-depth. This is used to make good allocations when doing dfs and bfs. Defaults to (0,None)

Source

fn with_depth(self, start_depth: Depth) -> LevelIter<Self>

Iterator Adapter to also produce the depth each iteration.

Source

fn zip<F: Visitor>(self, f: F) -> Zip<Self, F>

Combine two tree visitors.

Source

fn map<B, F: Fn(Self::Item) -> B>(self, func: F) -> Map<Self, F>

Map iterator adapter

Source

fn take(self, num: usize) -> Take<Self>

Only produce children up to num.

Source

fn flip(self) -> Flip<Self>

Flips left and right children.

Source

fn dfs_preorder_iter(self) -> DfsPreOrderIter<Self>

Provides a dfs preorder iterator. Unlike the callback version, This one relies on dynamic allocation for its stack.

Source

fn dfs_inorder_iter(self) -> DfsInOrderIter<Self>

Source

fn dfs_preorder(self, func: impl FnMut(Self::Item))

Calls the closure in dfs preorder (root,left,right). Takes advantage of the callstack to do dfs.

Source

fn dfs_inorder(self, func: impl FnMut(Self::Item))

Calls the closure in dfs preorder (left,right,root). Takes advantage of the callstack to do dfs.

Source

fn dfs_postorder(self, func: impl FnMut(Self::Item))

Calls the closure in dfs preorder (left,right,root). Takes advantage of the callstack to do dfs.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<'a, T: 'a> Visitor for Vistr<'a, T, InOrder>

Source§

impl<'a, T: 'a> Visitor for Vistr<'a, T, PostOrder>

Source§

impl<'a, T: 'a> Visitor for Vistr<'a, T, PreOrder>

Source§

impl<'a, T: 'a> Visitor for VistrMut<'a, T, InOrder>

Source§

impl<'a, T: 'a> Visitor for VistrMut<'a, T, PostOrder>

Source§

impl<'a, T: 'a> Visitor for VistrMut<'a, T, PreOrder>

Source§

impl<B, C: Visitor, F: Fn(C::Item) -> B + Clone> Visitor for Map<C, F>

Source§

type Item = B

Source§

impl<T1: Visitor, T2: Visitor> Visitor for Zip<T1, T2>

Source§

type Item = (<T1 as Visitor>::Item, <T2 as Visitor>::Item)

Source§

impl<T: Visitor> Visitor for Flip<T>

Source§

type Item = <T as Visitor>::Item

Source§

impl<T: Visitor> Visitor for LevelIter<T>

Source§

type Item = (Depth, <T as Visitor>::Item)

Source§

impl<T: Visitor> Visitor for Take<T>

Source§

type Item = <T as Visitor>::Item