From d29420c886d77095c99761f6deb71081f7bc8dcb Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Mon, 3 Feb 2025 09:04:47 +1300 Subject: Initial commit --- src/log_level.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/log_level.rs (limited to 'src/log_level.rs') diff --git a/src/log_level.rs b/src/log_level.rs new file mode 100644 index 0000000..6c84cb0 --- /dev/null +++ b/src/log_level.rs @@ -0,0 +1,37 @@ + +use std::cmp::Ordering; + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum LogLevel { + /// Verbose record of decisions and operations. + Info, + /// Report recoverable issues. + Warn, + /// Report unrecoverable errors and quit. + Error, +} + +impl PartialOrd for LogLevel { + fn partial_cmp(&self, other: &LogLevel) -> Option { + Some(self.cmp(other)) + } +} + +impl Ord for LogLevel { + fn cmp(&self, other: &LogLevel) -> Ordering { + use LogLevel::*; + match (self, other) { + (Info , Info ) => Ordering::Equal, + (Info , Warn ) => Ordering::Less, + (Info , Error) => Ordering::Less, + + (Warn , Info ) => Ordering::Greater, + (Warn , Warn ) => Ordering::Equal, + (Warn , Error) => Ordering::Less, + + (Error , Info ) => Ordering::Greater, + (Error , Warn ) => Ordering::Greater, + (Error , Error) => Ordering::Equal, + } + } +} -- cgit v1.2.3-70-g09d2