hex_patch/app/log/
notification.rs

1use std::fmt::{Display, Formatter};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, PartialOrd, Ord)]
4pub enum NotificationLevel {
5    #[default]
6    None = 0,
7    Debug = 1,
8    Info = 2,
9    Warning = 3,
10    Error = 4,
11}
12
13impl NotificationLevel {
14    pub fn bump_notification_level(&mut self, new_notification_level: NotificationLevel) {
15        if new_notification_level.notification_level_as_u8() > self.notification_level_as_u8() {
16            *self = new_notification_level;
17        }
18    }
19
20    pub fn reset(&mut self) {
21        *self = NotificationLevel::None;
22    }
23
24    pub fn notification_level_as_u8(&self) -> u8 {
25        *self as u8
26    }
27}
28
29impl From<u8> for NotificationLevel {
30    fn from(value: u8) -> Self {
31        match value {
32            0 => NotificationLevel::None,
33            1 => NotificationLevel::Debug,
34            2 => NotificationLevel::Info,
35            3 => NotificationLevel::Warning,
36            4 => NotificationLevel::Error,
37            _ => NotificationLevel::None,
38        }
39    }
40}
41
42impl Display for NotificationLevel {
43    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
44        match self {
45            NotificationLevel::None => write!(f, "None "),
46            NotificationLevel::Debug => write!(f, "Debug"),
47            NotificationLevel::Info => write!(f, "Info "),
48            NotificationLevel::Warning => write!(f, "Warn "),
49            NotificationLevel::Error => write!(f, "Error"),
50        }
51    }
52}