Skip to main content

proceed/
types.rs

1/// Ergonomic boolean flag for "false".
2pub const NO: bool = false;
3
4/// Ergonomic boolean flag for "true".
5pub const YES: bool = true;
6
7/// The abstraction around checking whether to proceed or not.
8pub trait Proceed {
9    /// Check if the input allows for proceeding.
10    /// If the input is empty, we return None.
11    fn proceed(&mut self) -> Option<bool>;
12
13    /// Check if the input allows for proceeding.
14    ///If the input is empty, return the given default.
15    fn proceed_or(&mut self, default: bool) -> bool {
16        self.proceed().unwrap_or(default)
17    }
18
19    /// Check if the input allows for proceeding.
20    /// If the input is empty, then run the given function.
21    fn proceed_or_else<F: FnOnce() -> bool>(&mut self, f: F) -> bool {
22        self.proceed().unwrap_or_else(f)
23    }
24}