From 540df66c77e1411a2c3902577818e818bbd7c7d3 Mon Sep 17 00:00:00 2001 From: Thaler Benedek Date: Mon, 11 Jul 2022 03:41:19 +0200 Subject: [PATCH] src/registry.rs: Remove Add trait impls (#69) They conflict with builtin implementations, see https://github.com/rust-lang/rust/issues/77143 Signed-off-by: Benedek Thaler --- CHANGELOG.md | 5 +++++ src/registry.rs | 27 ++++----------------------- 2 files changed, 9 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c9bb82a..1700c62d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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] diff --git a/src/registry.rs b/src/registry.rs index ae23cb63..ba2c2136 100644 --- a/src/registry.rs +++ b/src/registry.rs @@ -3,7 +3,6 @@ //! See [`Registry`] for details. use std::borrow::Cow; -use std::ops::Add; /// A metric registry. /// @@ -149,7 +148,7 @@ impl Registry { 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, @@ -196,13 +195,9 @@ impl Registry { /// but namespacing with a label instead of a metric name prefix. pub fn sub_registry_with_prefix>(&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() }; @@ -292,20 +287,6 @@ impl From 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,