1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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<Ordering> {
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,
}
}
}
|