1use std::borrow::Cow;
2use std::fmt;
3
4use serde::Serialize;
5
6#[derive(Debug, Clone, Eq, PartialEq, Serialize, Hash)]
11pub enum FilterStatKey {
12 IpAddress,
14
15 ReleaseVersion,
17
18 ErrorMessage,
20
21 BrowserExtensions,
23
24 LegacyBrowsers,
26
27 Localhost,
29
30 WebCrawlers,
32
33 InvalidCsp,
35
36 FilteredTransactions,
38
39 DeniedName,
41
42 DisabledNamespace,
44
45 Discarded,
49
50 GenericFilter(String),
52}
53
54impl FilterStatKey {
67 pub fn name(self) -> Cow<'static, str> {
69 Cow::Borrowed(match self {
70 FilterStatKey::IpAddress => "ip-address",
71 FilterStatKey::ReleaseVersion => "release-version",
72 FilterStatKey::ErrorMessage => "error-message",
73 FilterStatKey::BrowserExtensions => "browser-extensions",
74 FilterStatKey::LegacyBrowsers => "legacy-browsers",
75 FilterStatKey::Localhost => "localhost",
76 FilterStatKey::WebCrawlers => "web-crawlers",
77 FilterStatKey::InvalidCsp => "invalid-csp",
78 FilterStatKey::FilteredTransactions => "filtered-transaction",
79 FilterStatKey::DeniedName => "denied-name",
80 FilterStatKey::DisabledNamespace => "disabled-namespace",
81 FilterStatKey::Discarded => "discarded",
82 FilterStatKey::GenericFilter(filter_identifier) => {
83 return Cow::Owned(filter_identifier);
84 }
85 })
86 }
87}
88
89impl fmt::Display for FilterStatKey {
90 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
91 write!(f, "{}", self.clone().name())
92 }
93}
94
95impl<'a> TryFrom<&'a str> for FilterStatKey {
96 type Error = &'a str;
97
98 fn try_from(value: &'a str) -> Result<Self, Self::Error> {
99 Ok(match value {
100 "ip-address" => FilterStatKey::IpAddress,
101 "release-version" => FilterStatKey::ReleaseVersion,
102 "error-message" => FilterStatKey::ErrorMessage,
103 "browser-extensions" => FilterStatKey::BrowserExtensions,
104 "legacy-browsers" => FilterStatKey::LegacyBrowsers,
105 "localhost" => FilterStatKey::Localhost,
106 "web-crawlers" => FilterStatKey::WebCrawlers,
107 "invalid-csp" => FilterStatKey::InvalidCsp,
108 "filtered-transaction" => FilterStatKey::FilteredTransactions,
109 other => FilterStatKey::GenericFilter(other.to_owned()),
110 })
111 }
112}