mock_http_connector/level.rs
1/// Diagnostic levels
2///
3/// ## Default
4///
5/// [`Level`] implements [`Default`], which will return `Level::Missing`.
6///
7/// ```rust
8/// use mock_http_connector::Level;
9///
10/// assert_eq!(Level::default(), Level::Missing);
11/// ```
12///
13/// ## Ordering
14///
15/// [`Level`] implements [`PartialOrd`] and [`Ord`] to facilitates comparing two [`Level`]s to
16/// know which one is more verbose. The one with a greater value will be more verbose than the
17/// other.
18///
19/// ```rust
20/// use mock_http_connector::Level;
21///
22/// assert!(Level::Error < Level::Missing);
23/// assert!(Level::None < Level::Error);
24/// assert_eq!(Level::Missing, Level::Missing);
25/// ```
26///
27/// ## Internal value guarantees
28///
29/// This enum implements [`PartialOrd`] and [`Ord`] through an internal representation as `u8`.
30/// However, there is no guarantees that the actual integer values for each enum variants will
31/// stay consistent from version to version.
32///
33/// If you want to compare a [`Level`] to a certain value, you should always compare it to a
34/// [`Level`] and not to an integer.
35#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
36#[repr(u8)]
37pub enum Level {
38 /// Display information when no cases match the incoming request
39 #[default]
40 Missing = 2,
41 /// Display diagnostic information on errors
42 Error = 1,
43 /// Never display diagnostic information
44 None = 0,
45}
46
47impl PartialOrd for Level {
48 fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
49 Some(self.cmp(other))
50 }
51}
52
53impl Ord for Level {
54 fn cmp(&self, other: &Self) -> std::cmp::Ordering {
55 (*self as u8).cmp(&(*other as u8))
56 }
57}