Skip to content

Commit cab00f7

Browse files
author
Elias Ram
committed
removed From trait
1 parent 835f025 commit cab00f7

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

sentry-core/src/metrics/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -534,11 +534,11 @@ impl Metric {
534534
.as_secs();
535535
let data = format!(
536536
"{}@{}:{}|{}|#{}|T{}",
537-
NormalizedName::from(self.name.as_ref()),
538-
NormalizedUnit::from(self.unit.to_string().as_ref()),
537+
NormalizedName::from_str(self.name.as_ref()),
538+
NormalizedUnit::from_str(self.unit.to_string().as_ref()),
539539
self.value,
540540
self.value.ty(),
541-
NormalizedTags::from(&self.tags),
541+
NormalizedTags::from_tag_map(&self.tags),
542542
timestamp
543543
);
544544
EnvelopeItem::Statsd(data.into_bytes()).into()
@@ -836,10 +836,10 @@ impl Worker {
836836

837837
for (timestamp, buckets) in buckets {
838838
for (key, value) in buckets {
839-
write!(&mut out, "{}", NormalizedName::from(key.name.as_ref()))?;
839+
write!(&mut out, "{}", NormalizedName::from_str(key.name.as_ref()))?;
840840
match key.unit {
841841
MetricUnit::Custom(u) => {
842-
write!(&mut out, "@{}", NormalizedUnit::from(u.as_ref()))?
842+
write!(&mut out, "@{}", NormalizedUnit::from_str(u.as_ref()))?
843843
}
844844
_ => write!(&mut out, "@{}", key.unit)?,
845845
}
@@ -868,7 +868,7 @@ impl Worker {
868868

869869
write!(&mut out, "|{}", key.ty.as_str())?;
870870
let normalized_tags =
871-
NormalizedTags::from(&key.tags).with_default_tags(&self.default_tags);
871+
NormalizedTags::from_tag_map(&key.tags).with_default_tags(&self.default_tags);
872872
write!(&mut out, "|#{}", normalized_tags)?;
873873
writeln!(&mut out, "|T{}", timestamp)?;
874874
}

sentry-core/src/metrics/normalization/normalized_name.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ pub struct NormalizedName<'a> {
66
name: Cow<'a, str>,
77
}
88

9-
impl<'a> From<&'a str> for NormalizedName<'a> {
10-
fn from(name: &'a str) -> Self {
9+
impl<'a> NormalizedName<'a> {
10+
pub fn from_str(name: &'a str) -> Self {
1111
static METRIC_NAME_RE: OnceLock<Regex> = OnceLock::new();
1212
Self {
1313
name: METRIC_NAME_RE
@@ -31,7 +31,7 @@ mod test {
3131
fn test_from() {
3232
let expected = "aA1_-.____________";
3333

34-
let actual = NormalizedName::from("aA1_-./+ö{😀\n\t\r\\| ,").to_string();
34+
let actual = NormalizedName::from_str("aA1_-./+ö{😀\n\t\r\\| ,").to_string();
3535

3636
assert_eq!(expected, actual);
3737
}
@@ -40,7 +40,7 @@ mod test {
4040
fn test_length_restriction() {
4141
let expected = "a".repeat(150);
4242

43-
let actual = NormalizedName::from("a".repeat(155).as_ref()).to_string();
43+
let actual = NormalizedName::from_str("a".repeat(155).as_ref()).to_string();
4444

4545
assert_eq!(expected, actual);
4646
}

sentry-core/src/metrics/normalization/normalized_tags.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ pub struct NormalizedTags<'a> {
88
tags: HashMap<Cow<'a, str>, String>,
99
}
1010

11-
impl<'a> From<&'a TagMap> for NormalizedTags<'a> {
12-
fn from(tags: &'a TagMap) -> Self {
11+
impl<'a> NormalizedTags<'a> {
12+
pub fn from_tag_map(tags: &'a TagMap) -> Self {
1313
Self {
1414
tags: tags
1515
.iter()
@@ -95,7 +95,7 @@ mod test {
9595
);
9696
let expected = "aa:a\\na,bb:b\\rb,cc:c\\tc,dd:d\\\\d,ee:e\\u{7c}e,ff:f\\u{2c}f";
9797

98-
let actual = NormalizedTags::from(&tags).to_string();
98+
let actual = NormalizedTags::from_tag_map(&tags).to_string();
9999

100100
assert_eq!(expected, actual);
101101
}
@@ -109,7 +109,7 @@ mod test {
109109
);
110110
let expected = "";
111111

112-
let actual = NormalizedTags::from(&tags).to_string();
112+
let actual = NormalizedTags::from_tag_map(&tags).to_string();
113113

114114
assert_eq!(expected, actual);
115115
}
@@ -119,7 +119,7 @@ mod test {
119119
let tags = TagMap::from([("aA1_-./+ö{ 😀".into(), "aA1_-./+ö{ 😀".into())]);
120120
let expected = "aA1_-./:aA1_-./+ö{ 😀";
121121

122-
let actual = NormalizedTags::from(&tags).to_string();
122+
let actual = NormalizedTags::from_tag_map(&tags).to_string();
123123

124124
assert_eq!(expected, actual);
125125
}
@@ -132,7 +132,7 @@ mod test {
132132
]);
133133
let expected = "environment:production,release:default_release";
134134

135-
let actual = NormalizedTags::from(&TagMap::new())
135+
let actual = NormalizedTags::from_tag_map(&TagMap::new())
136136
.with_default_tags(&default_tags)
137137
.to_string();
138138

@@ -147,7 +147,7 @@ mod test {
147147
]);
148148
let expected = "environment:custom_env,release:custom_release";
149149

150-
let actual = NormalizedTags::from(&TagMap::from([
150+
let actual = NormalizedTags::from_tag_map(&TagMap::from([
151151
("release".into(), "custom_release".into()),
152152
("environment".into(), "custom_env".into()),
153153
]))
@@ -167,7 +167,7 @@ mod test {
167167
+ ":"
168168
+ "v".repeat(200).as_str();
169169

170-
let actual = NormalizedTags::from(&TagMap::from([(
170+
let actual = NormalizedTags::from_tag_map(&TagMap::from([(
171171
"k".repeat(35).into(),
172172
"v".repeat(210).into(),
173173
)]))

sentry-core/src/metrics/normalization/normalized_unit.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ pub struct NormalizedUnit<'a> {
88
unit: Cow<'a, str>,
99
}
1010

11-
impl<'a> From<&'a str> for NormalizedUnit<'a> {
12-
fn from(unit: &'a str) -> Self {
11+
impl<'a> NormalizedUnit<'a> {
12+
pub fn from_str(unit: &'a str) -> Self {
1313
static METRIC_UNIT_RE: OnceLock<Regex> = OnceLock::new();
1414
let normalized_unit = METRIC_UNIT_RE
1515
.get_or_init(|| Regex::new(r"[^a-zA-Z0-9_]").expect("Regex should compile"))
@@ -37,7 +37,7 @@ mod test {
3737
fn test_from() {
3838
let expected = "aA1_";
3939

40-
let actual = NormalizedUnit::from("aA1_-./+ö{😀\n\t\r\\| ,").to_string();
40+
let actual = NormalizedUnit::from_str("aA1_-./+ö{😀\n\t\r\\| ,").to_string();
4141

4242
assert_eq!(expected, actual);
4343
}
@@ -46,7 +46,7 @@ mod test {
4646
fn test_from_empty() {
4747
let expected = "none";
4848

49-
let actual = NormalizedUnit::from("").to_string();
49+
let actual = NormalizedUnit::from_str("").to_string();
5050

5151
assert_eq!(expected, actual);
5252
}
@@ -55,7 +55,7 @@ mod test {
5555
fn test_from_empty_after_normalization() {
5656
let expected = "none";
5757

58-
let actual = NormalizedUnit::from("+").to_string();
58+
let actual = NormalizedUnit::from_str("+").to_string();
5959

6060
assert_eq!(expected, actual);
6161
}
@@ -64,7 +64,7 @@ mod test {
6464
fn test_length_restriction() {
6565
let expected = "a".repeat(15);
6666

67-
let actual = NormalizedUnit::from("a".repeat(20).as_ref()).to_string();
67+
let actual = NormalizedUnit::from_str("a".repeat(20).as_ref()).to_string();
6868

6969
assert_eq!(expected, actual);
7070
}

0 commit comments

Comments
 (0)