cursive-tree 0.0.9

Tree view for the Cursive TUI library
Documentation
//
// Depth
//

/// Tree node depth.
pub trait Depth {
    /// Whether we are 0.
    fn is_zero(&self) -> bool;

    /// Decrease by 1 if we are greater than 0.
    fn decrease(&mut self);
}

impl Depth for Option<usize> {
    fn is_zero(&self) -> bool {
        self.map(|depth| depth == 0).unwrap_or_default()
    }

    fn decrease(&mut self) {
        *self = self.map(|depth| if depth > 1 { depth - 1 } else { 0 });
    }
}