killswitch/cli/
verbosity.rs1#[derive(Debug, Clone, Copy)]
3pub enum Verbosity {
4 Normal,
5 Verbose,
6 Debug,
7}
8
9impl From<u8> for Verbosity {
10 fn from(count: u8) -> Self {
11 match count {
12 0 => Self::Normal,
13 1 => Self::Verbose,
14 _ => Self::Debug,
15 }
16 }
17}
18
19impl Verbosity {
20 #[must_use]
22 pub const fn is_verbose(self) -> bool {
23 matches!(self, Self::Verbose | Self::Debug)
24 }
25
26 #[must_use]
28 pub const fn is_debug(self) -> bool {
29 matches!(self, Self::Debug)
30 }
31}
32
33#[cfg(test)]
34mod tests {
35 use super::*;
36
37 #[test]
38 fn test_verbosity_from_count() {
39 assert!(matches!(Verbosity::from(0), Verbosity::Normal));
40 assert!(matches!(Verbosity::from(1), Verbosity::Verbose));
41 assert!(matches!(Verbosity::from(2), Verbosity::Debug));
42 assert!(matches!(Verbosity::from(3), Verbosity::Debug));
43 assert!(matches!(Verbosity::from(10), Verbosity::Debug));
44 }
45
46 #[test]
47 fn test_verbosity_is_verbose() {
48 assert!(!Verbosity::Normal.is_verbose());
49 assert!(Verbosity::Verbose.is_verbose());
50 assert!(Verbosity::Debug.is_verbose());
51 }
52
53 #[test]
54 fn test_verbosity_is_debug() {
55 assert!(!Verbosity::Normal.is_debug());
56 assert!(!Verbosity::Verbose.is_debug());
57 assert!(Verbosity::Debug.is_debug());
58 }
59}