Skip to main content

cursive_tree/model/
depth.rs

1//
2// Depth
3//
4
5/// Tree node depth.
6pub trait Depth {
7    /// Whether we are 0.
8    fn is_zero(&self) -> bool;
9
10    /// Decrease by 1 if we are greater than 0.
11    fn decrease(&mut self);
12}
13
14impl Depth for Option<usize> {
15    fn is_zero(&self) -> bool {
16        self.map(|depth| depth == 0).unwrap_or_default()
17    }
18
19    fn decrease(&mut self) {
20        *self = self.map(|depth| if depth > 1 { depth - 1 } else { 0 });
21    }
22}