-
Notifications
You must be signed in to change notification settings - Fork 540
/
Copy pathwarning.rs
42 lines (32 loc) · 887 Bytes
/
warning.rs
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
38
39
40
41
42
use super::*;
#[derive(Clone, Debug, PartialEq)]
pub(crate) enum Warning {}
impl Warning {
#[allow(clippy::unused_self)]
fn context(&self) -> Option<&Token> {
None
}
}
impl ColorDisplay for Warning {
fn fmt(&self, f: &mut Formatter, color: Color) -> fmt::Result {
let warning = color.warning();
let message = color.message();
write!(f, "{} {}", warning.paint("warning:"), message.prefix())?;
write!(f, "{}", message.suffix())?;
if let Some(token) = self.context() {
writeln!(f)?;
write!(f, "{}", token.color_display(color))?;
}
Ok(())
}
}
impl Serialize for Warning {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("message", &self.color_display(Color::never()).to_string())?;
map.end()
}
}