Skip to content

Commit c54ac6e

Browse files
committed
src/registry.rs: Remove Add trait impls
They interact with builtin implementation in confusing ways: rust-lang/rust#77143 Fixes prometheus#68 Signed-off-by: Benedek Thaler <[email protected]>
1 parent 69e6674 commit c54ac6e

File tree

2 files changed

+9
-23
lines changed

2 files changed

+9
-23
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010

1111
- Updates to Rust 2021 Edition. See [PR 65].
1212

13+
### Removed
14+
15+
- Remove Add trait implementation for a private type. See [PR 69].
16+
1317
[PR 65]: https://github.com/prometheus/client_rust/pull/65
18+
[PR 69]: https://github.com/prometheus/client_rust/pull/69
1419

1520
## [0.16.0]
1621

src/registry.rs

+4-23
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//! See [`Registry`] for details.
44
55
use std::borrow::Cow;
6-
use std::ops::Add;
76

87
/// A metric registry.
98
///
@@ -149,7 +148,7 @@ impl<M> Registry<M> {
149148
name: self
150149
.prefix
151150
.as_ref()
152-
.map(|p| (p.clone() + "_" + name.as_str()).into())
151+
.map(|p| (p.clone().0 + "_" + name.as_str()))
153152
.unwrap_or(name),
154153
help,
155154
unit,
@@ -196,13 +195,9 @@ impl<M> Registry<M> {
196195
/// but namespacing with a label instead of a metric name prefix.
197196
pub fn sub_registry_with_prefix<P: AsRef<str>>(&mut self, prefix: P) -> &mut Self {
198197
let sub_registry = Registry {
199-
prefix: Some(
200-
self.prefix
201-
.clone()
202-
.map(|p| p + "_")
203-
.unwrap_or_else(|| String::new().into())
204-
+ prefix.as_ref(),
205-
),
198+
prefix: Some(Prefix(
199+
self.prefix.clone().map(|p| p.0 + "_").unwrap_or_default() + prefix.as_ref(),
200+
)),
206201
labels: self.labels.clone(),
207202
..Default::default()
208203
};
@@ -292,20 +287,6 @@ impl From<Prefix> for String {
292287
}
293288
}
294289

295-
impl Add<&str> for Prefix {
296-
type Output = Self;
297-
fn add(self, rhs: &str) -> Self::Output {
298-
Prefix(self.0 + rhs)
299-
}
300-
}
301-
302-
impl Add<&Prefix> for String {
303-
type Output = Self;
304-
fn add(self, rhs: &Prefix) -> Self::Output {
305-
self + rhs.0.as_str()
306-
}
307-
}
308-
309290
pub struct Descriptor {
310291
name: String,
311292
help: String,

0 commit comments

Comments
 (0)