tree_iter/traversal_order.rs
1/// Marker struct representing breadth-first traversal order.
2///
3/// Breadth-first traversal visits all nodes at the same depth level before moving to the next level.
4/// This is implemented using a queue where children are added to the back of the queue.
5#[derive(Debug)]
6pub struct BreadthFirst;
7
8/// Marker struct representing depth-first traversal order.
9///
10/// Depth-first traversal explores as far down a branch as possible before backtracking.
11/// This is implemented by adding children to the front of the queue or using a stack.
12#[derive(Debug)]
13pub struct DepthFirst;
14
15/// Private module to implement the sealed trait pattern.
16///
17/// This prevents external crates from implementing the `TraversalOrder` trait,
18/// allowing us to maintain control over the possible traversal orders.
19mod seal {
20 pub trait Sealed {}
21 impl Sealed for super::DepthFirst {}
22 impl Sealed for super::BreadthFirst {}
23}
24
25/// Trait for tree traversal order strategies.
26///
27/// This trait is sealed (cannot be implemented outside this crate) and is used as
28/// a marker for different traversal strategies that can be used with tree iterators.
29pub trait TraversalOrder: seal::Sealed {}
30impl TraversalOrder for BreadthFirst {}
31impl TraversalOrder for DepthFirst {}