iter_tree/nesting_function.rs
1/// The [`Nesting`] enum is used to control the creation of trees.
2// This enum has three variants :
3
4/// - [`Nesting::Increase`]
5/// - Is used to start nesting the items of the iterator into a new node.
6/// - [`Nesting::Maintain`]
7/// - Is used to keep the item in the same node as the previous ones
8/// - [`Nesting::Decrease`]
9/// - Is used to get back up to the previous node to put the next items. If there is no previous branch a new parent branch is then created.
10
11/// If you want to check for these kind of situations, you can use a the depth counter.
12pub enum Nesting {
13 /// Used to start nesting the items of the iterator into a new node.
14 Increase,
15 /// Used to keep the item in the same node as the previous ones.
16 Maintain,
17 /// Used to get back up to the previous node to put the next items. If there is no previous branch a new parent branch is then created.
18 Decrease,
19}
20
21pub trait NestingFunction<T> {
22 fn direction(&mut self, item: &T) -> Nesting;
23}
24
25impl<T, F> NestingFunction<T> for F
26where
27 F: FnMut(&T) -> Nesting,
28{
29 fn direction(&mut self, item: &T) -> Nesting {
30 (self)(item)
31 }
32}