1use std::fmt::{self, Display, Formatter};
4
5use crate::diagnostic_filter::{
6 FilterableTriggeringRule, Severity, StandardFilterableTriggeringRule,
7};
8
9impl Severity {
10 const ERROR: &'static str = "error";
11 const WARNING: &'static str = "warning";
12 const INFO: &'static str = "info";
13 const OFF: &'static str = "off";
14
15 pub fn from_wgsl_ident(s: &str) -> Option<Self> {
17 Some(match s {
18 Self::ERROR => Self::Error,
19 Self::WARNING => Self::Warning,
20 Self::INFO => Self::Info,
21 Self::OFF => Self::Off,
22 _ => return None,
23 })
24 }
25}
26
27struct DisplayFilterableTriggeringRule<'a>(&'a FilterableTriggeringRule);
28
29impl Display for DisplayFilterableTriggeringRule<'_> {
30 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
31 let &Self(inner) = self;
32 match *inner {
33 FilterableTriggeringRule::Standard(rule) => write!(f, "{}", rule.to_wgsl_ident()),
34 FilterableTriggeringRule::Unknown(ref rule) => write!(f, "{rule}"),
35 FilterableTriggeringRule::User(ref rules) => {
36 let &[ref seg1, ref seg2] = rules.as_ref();
37 write!(f, "{seg1}.{seg2}")
38 }
39 }
40 }
41}
42
43impl FilterableTriggeringRule {
44 pub const fn display_wgsl_ident(&self) -> impl Display + '_ {
46 DisplayFilterableTriggeringRule(self)
47 }
48}
49
50impl StandardFilterableTriggeringRule {
51 const DERIVATIVE_UNIFORMITY: &'static str = "derivative_uniformity";
52
53 pub fn from_wgsl_ident(s: &str) -> Option<Self> {
56 Some(match s {
57 Self::DERIVATIVE_UNIFORMITY => Self::DerivativeUniformity,
58 _ => return None,
59 })
60 }
61
62 pub const fn to_wgsl_ident(self) -> &'static str {
65 match self {
66 Self::DerivativeUniformity => Self::DERIVATIVE_UNIFORMITY,
67 }
68 }
69}