Skip to content

Commit 970606a

Browse files
authored
feat: impl<T: Collector> Collector for std::sync::Arc<T> (prometheus#273)
Signed-off-by: hanabi1224 <[email protected]>
1 parent 1d5824a commit 970606a

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
- `Family::get_or_create_owned` can access a metric in a labeled family. This
1515
method avoids the risk of runtime deadlocks at the expense of creating an
1616
owned type. See [PR 244].
17+
18+
- `impl<T: Collector> Collector for std::sync::Arc<T>`.
19+
See [PR 273].
1720

1821
[PR 244]: https://github.com/prometheus/client_rust/pull/244
1922
[PR 257]: https://github.com/prometheus/client_rust/pull/257
23+
[PR 273]: https://github.com/prometheus/client_rust/pull/273
2024

2125
### Changed
2226

src/collector.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,9 @@ pub trait Collector: std::fmt::Debug + Send + Sync + 'static {
3939
/// Once the [`Collector`] is registered, this method is called on each scrape.
4040
fn encode(&self, encoder: DescriptorEncoder) -> Result<(), std::fmt::Error>;
4141
}
42+
43+
impl<T: Collector> Collector for std::sync::Arc<T> {
44+
fn encode(&self, encoder: DescriptorEncoder) -> Result<(), std::fmt::Error> {
45+
self.as_ref().encode(encoder)
46+
}
47+
}

0 commit comments

Comments
 (0)