Skip to content

Commit

Permalink
src/registry.rs: Remove Add trait impls (prometheus#69)
Browse files Browse the repository at this point in the history
They conflict with builtin implementations, see
rust-lang/rust#77143

Signed-off-by: Benedek Thaler <erenon2@gmail.com>
Signed-off-by: ackintosh <sora.akatsuki@gmail.com>
  • Loading branch information
erenon authored and ackintosh committed Aug 27, 2022
1 parent 0f0f70e commit 496c8ab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 23 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

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

### Removed

- Remove `Add` trait implementation for a private type which lead to compile time conflicts with existing `Add` implementations e.g. on `String`. See [PR 69].

[PR 65]: https://github.com/prometheus/client_rust/pull/65
[PR 69]: https://github.com/prometheus/client_rust/pull/69

## [0.16.0]

Expand Down
27 changes: 4 additions & 23 deletions src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
//! See [`Registry`] for details.

use std::borrow::Cow;
use std::ops::Add;

/// A metric registry.
///
Expand Down Expand Up @@ -149,7 +148,7 @@ impl<M> Registry<M> {
name: self
.prefix
.as_ref()
.map(|p| (p.clone() + "_" + name.as_str()).into())
.map(|p| (p.clone().0 + "_" + name.as_str()))
.unwrap_or(name),
help,
unit,
Expand Down Expand Up @@ -196,13 +195,9 @@ impl<M> Registry<M> {
/// but namespacing with a label instead of a metric name prefix.
pub fn sub_registry_with_prefix<P: AsRef<str>>(&mut self, prefix: P) -> &mut Self {
let sub_registry = Registry {
prefix: Some(
self.prefix
.clone()
.map(|p| p + "_")
.unwrap_or_else(|| String::new().into())
+ prefix.as_ref(),
),
prefix: Some(Prefix(
self.prefix.clone().map(|p| p.0 + "_").unwrap_or_default() + prefix.as_ref(),
)),
labels: self.labels.clone(),
..Default::default()
};
Expand Down Expand Up @@ -292,20 +287,6 @@ impl From<Prefix> for String {
}
}

impl Add<&str> for Prefix {
type Output = Self;
fn add(self, rhs: &str) -> Self::Output {
Prefix(self.0 + rhs)
}
}

impl Add<&Prefix> for String {
type Output = Self;
fn add(self, rhs: &Prefix) -> Self::Output {
self + rhs.0.as_str()
}
}

pub struct Descriptor {
name: String,
help: String,
Expand Down

0 comments on commit 496c8ab

Please sign in to comment.