ferrin_spec/shared/
warning.rs1use serde::Deserialize;
4use serde::Serialize;
5
6#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
11#[serde(tag = "type", rename_all = "kebab-case")]
12#[non_exhaustive]
13pub enum Warning {
14 Unsupported {
16 feature: String,
18 #[serde(default, skip_serializing_if = "Option::is_none")]
20 details: Option<String>,
21 },
22 Compatibility {
24 feature: String,
26 #[serde(default, skip_serializing_if = "Option::is_none")]
28 details: Option<String>,
29 },
30 Deprecated {
32 setting: String,
34 message: String,
36 },
37 Other {
39 message: String,
41 },
42}
43
44impl Warning {
45 #[must_use]
47 pub fn unsupported(feature: impl Into<String>) -> Self {
48 Self::Unsupported {
49 feature: feature.into(),
50 details: None,
51 }
52 }
53
54 #[must_use]
56 pub fn unsupported_with_details(
57 feature: impl Into<String>,
58 details: impl Into<String>,
59 ) -> Self {
60 Self::Unsupported {
61 feature: feature.into(),
62 details: Some(details.into()),
63 }
64 }
65
66 #[must_use]
68 pub fn compatibility(feature: impl Into<String>, details: Option<String>) -> Self {
69 Self::Compatibility {
70 feature: feature.into(),
71 details,
72 }
73 }
74
75 #[must_use]
77 pub fn deprecated(setting: impl Into<String>, message: impl Into<String>) -> Self {
78 Self::Deprecated {
79 setting: setting.into(),
80 message: message.into(),
81 }
82 }
83
84 #[must_use]
86 pub fn other(message: impl Into<String>) -> Self {
87 Self::Other {
88 message: message.into(),
89 }
90 }
91}
92
93impl std::fmt::Display for Warning {
94 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
95 match self {
96 Self::Unsupported { feature, details } => match details {
97 Some(details) => write!(f, "unsupported {feature}: {details}"),
98 None => write!(f, "unsupported {feature}"),
99 },
100 Self::Compatibility { feature, details } => match details {
101 Some(details) => write!(f, "compatibility for {feature}: {details}"),
102 None => write!(f, "compatibility for {feature}"),
103 },
104 Self::Deprecated { setting, message } => {
105 write!(f, "deprecated setting {setting}: {message}")
106 }
107 Self::Other { message } => f.write_str(message),
108 }
109 }
110}