1#[non_exhaustive]
5#[repr(u8)]
6#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
7pub enum Level {
8 #[default]
10 None,
11 Note,
13 Help,
15 Warning,
17 Error,
19}
20
21impl Level {
22 pub fn to_u8(&self) -> u8 {
24 *self as u8
25 }
26
27 pub fn as_str(&self) -> &'static str {
29 match self {
30 Self::None => "none",
31 Self::Error => "error",
32 Self::Warning => "warning",
33 Self::Note => "note",
34 Self::Help => "help",
35 }
36 }
37}
38
39impl std::fmt::Display for Level {
40 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
41 write!(f, "{}", self.as_str())
42 }
43}
44
45#[cfg(feature = "diagnostics")]
46impl From<proc_macro2_diagnostics::Level> for Level {
47 fn from(value: proc_macro2_diagnostics::Level) -> Self {
48 match value {
49 proc_macro2_diagnostics::Level::Error => Self::Error,
50 proc_macro2_diagnostics::Level::Warning => Self::Warning,
51 proc_macro2_diagnostics::Level::Note => Self::Note,
52 proc_macro2_diagnostics::Level::Help => Self::Help,
53 _ => Self::None,
54 }
55 }
56}
57
58#[cfg(feature = "diagnostics")]
59impl From<Level> for proc_macro2_diagnostics::Level {
60 fn from(value: Level) -> Self {
61 match value {
62 Level::Error => Self::Error,
63 Level::Warning => Self::Warning,
64 Level::Note => Self::Note,
65 Level::Help => Self::Help,
66 Level::None => panic!("unsupported diagnostic level"),
67 }
68 }
69}