Skip to content

Commit 80fe980

Browse files
authored
Merge branch 'master' into impl-collector-for-arc
2 parents c8c87c3 + 1d5824a commit 80fe980

File tree

11 files changed

+31
-25
lines changed

11 files changed

+31
-25
lines changed

benches/encoding/proto.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,20 @@ pub fn proto(c: &mut Criterion) {
4747
});
4848

4949
registry.register(
50-
format!("my_counter{}", i),
50+
format!("my_counter{i}"),
5151
"My counter",
5252
counter_family.clone(),
5353
);
5454
registry.register(
55-
format!("my_histogram{}", i),
55+
format!("my_histogram{i}"),
5656
"My histogram",
5757
histogram_family.clone(),
5858
);
5959

6060
for j in 0_u32..100 {
6161
counter_family
6262
.get_or_create(&CounterLabels {
63-
path: format!("/path/{}", i),
63+
path: format!("/path/{i}"),
6464
method: Method::Get,
6565
some_number: j.into(),
6666
})

benches/encoding/text.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ pub fn text(c: &mut Criterion) {
5454
});
5555

5656
registry.register(
57-
format!("my_counter_{}", i),
57+
format!("my_counter_{i}"),
5858
"My counter",
5959
counter_family.clone(),
6060
);
6161
registry.register(
62-
format!("my_histogram_{}", i),
62+
format!("my_histogram_{i}"),
6363
"My histogram",
6464
histogram_family.clone(),
6565
);

examples/axum.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ async fn main() {
8080
.route("/handler", get(some_handler))
8181
.with_state(metrics);
8282
let port = 8080;
83-
let listener = tokio::net::TcpListener::bind(format!("0.0.0.0:{}", port))
83+
let listener = tokio::net::TcpListener::bind(format!("0.0.0.0:{port}"))
8484
.await
8585
.unwrap();
8686

examples/custom-metric.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ fn main() {
4141
let mut encoded = String::new();
4242
encode(&mut encoded, &registry).unwrap();
4343

44-
println!("Scrape output:\n{:?}", encoded);
44+
println!("Scrape output:\n{encoded:?}");
4545
}

examples/hyper.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub fn make_handler(
7676
Box::pin(async move {
7777
let mut buf = String::new();
7878
encode(&mut buf, &reg.clone())
79-
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))
79+
.map_err(std::io::Error::other)
8080
.map(|_| {
8181
let body = full(Bytes::from(buf));
8282
Response::builder()

src/encoding.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ impl<'a> From<protobuf::LabelSetEncoder<'a>> for LabelSetEncoder<'a> {
232232

233233
impl LabelSetEncoder<'_> {
234234
/// Encode the given label.
235-
pub fn encode_label(&mut self) -> LabelEncoder {
235+
pub fn encode_label(&mut self) -> LabelEncoder<'_> {
236236
for_both_mut!(self, LabelSetEncoderInner, e, e.encode_label().into())
237237
}
238238
}
@@ -321,7 +321,7 @@ impl<'a> From<protobuf::LabelEncoder<'a>> for LabelEncoder<'a> {
321321

322322
impl LabelEncoder<'_> {
323323
/// Encode a label.
324-
pub fn encode_label_key(&mut self) -> Result<LabelKeyEncoder, std::fmt::Error> {
324+
pub fn encode_label_key(&mut self) -> Result<LabelKeyEncoder<'_>, std::fmt::Error> {
325325
for_both_mut!(
326326
self,
327327
LabelEncoderInner,
@@ -415,6 +415,7 @@ impl EncodeLabelKey for Cow<'_, str> {
415415

416416
impl<T> EncodeLabelKey for Box<T>
417417
where
418+
T: ?Sized,
418419
for<'a> &'a T: EncodeLabelKey,
419420
{
420421
fn encode(&self, encoder: &mut LabelKeyEncoder) -> Result<(), std::fmt::Error> {
@@ -424,6 +425,7 @@ where
424425

425426
impl<T> EncodeLabelKey for Arc<T>
426427
where
428+
T: ?Sized,
427429
for<'a> &'a T: EncodeLabelKey,
428430
{
429431
fn encode(&self, encoder: &mut LabelKeyEncoder) -> Result<(), std::fmt::Error> {
@@ -433,6 +435,7 @@ where
433435

434436
impl<T> EncodeLabelKey for Rc<T>
435437
where
438+
T: ?Sized,
436439
for<'a> &'a T: EncodeLabelKey,
437440
{
438441
fn encode(&self, encoder: &mut LabelKeyEncoder) -> Result<(), std::fmt::Error> {
@@ -510,6 +513,7 @@ impl EncodeLabelValue for Cow<'_, str> {
510513

511514
impl<T> EncodeLabelValue for Box<T>
512515
where
516+
T: ?Sized,
513517
for<'a> &'a T: EncodeLabelValue,
514518
{
515519
fn encode(&self, encoder: &mut LabelValueEncoder) -> Result<(), std::fmt::Error> {
@@ -519,6 +523,7 @@ where
519523

520524
impl<T> EncodeLabelValue for Arc<T>
521525
where
526+
T: ?Sized,
522527
for<'a> &'a T: EncodeLabelValue,
523528
{
524529
fn encode(&self, encoder: &mut LabelValueEncoder) -> Result<(), std::fmt::Error> {
@@ -528,6 +533,7 @@ where
528533

529534
impl<T> EncodeLabelValue for Rc<T>
530535
where
536+
T: ?Sized,
531537
for<'a> &'a T: EncodeLabelValue,
532538
{
533539
fn encode(&self, encoder: &mut LabelValueEncoder) -> Result<(), std::fmt::Error> {

src/encoding/protobuf.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub(crate) struct DescriptorEncoder<'a> {
7272
impl DescriptorEncoder<'_> {
7373
pub(crate) fn new(
7474
metric_families: &mut Vec<openmetrics_data_model::MetricFamily>,
75-
) -> DescriptorEncoder {
75+
) -> DescriptorEncoder<'_> {
7676
DescriptorEncoder {
7777
metric_families,
7878
prefix: Default::default(),
@@ -232,7 +232,7 @@ impl MetricEncoder<'_> {
232232
pub fn encode_family<S: EncodeLabelSet>(
233233
&mut self,
234234
label_set: &S,
235-
) -> Result<MetricEncoder, std::fmt::Error> {
235+
) -> Result<MetricEncoder<'_>, std::fmt::Error> {
236236
let mut labels = self.labels.clone();
237237
label_set.encode(
238238
&mut LabelSetEncoder {
@@ -382,7 +382,7 @@ pub(crate) struct LabelSetEncoder<'a> {
382382
}
383383

384384
impl LabelSetEncoder<'_> {
385-
pub fn encode_label(&mut self) -> LabelEncoder {
385+
pub fn encode_label(&mut self) -> LabelEncoder<'_> {
386386
LabelEncoder {
387387
labels: self.labels,
388388
}
@@ -395,7 +395,7 @@ pub(crate) struct LabelEncoder<'a> {
395395
}
396396

397397
impl LabelEncoder<'_> {
398-
pub fn encode_label_key(&mut self) -> Result<LabelKeyEncoder, std::fmt::Error> {
398+
pub fn encode_label_key(&mut self) -> Result<LabelKeyEncoder<'_>, std::fmt::Error> {
399399
self.labels.push(openmetrics_data_model::Label::default());
400400

401401
Ok(LabelKeyEncoder {

src/encoding/text.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl std::fmt::Debug for DescriptorEncoder<'_> {
195195
}
196196

197197
impl DescriptorEncoder<'_> {
198-
pub(crate) fn new(writer: &mut dyn Write) -> DescriptorEncoder {
198+
pub(crate) fn new(writer: &mut dyn Write) -> DescriptorEncoder<'_> {
199199
DescriptorEncoder {
200200
writer,
201201
prefix: Default::default(),
@@ -643,7 +643,7 @@ impl<'a> LabelSetEncoder<'a> {
643643
}
644644
}
645645

646-
pub fn encode_label(&mut self) -> LabelEncoder {
646+
pub fn encode_label(&mut self) -> LabelEncoder<'_> {
647647
let first = self.first;
648648
self.first = false;
649649
LabelEncoder {
@@ -667,7 +667,7 @@ impl std::fmt::Debug for LabelEncoder<'_> {
667667
}
668668

669669
impl LabelEncoder<'_> {
670-
pub fn encode_label_key(&mut self) -> Result<LabelKeyEncoder, std::fmt::Error> {
670+
pub fn encode_label_key(&mut self) -> Result<LabelKeyEncoder<'_>, std::fmt::Error> {
671671
if !self.first {
672672
self.writer.write_str(",")?;
673673
}
@@ -1218,7 +1218,7 @@ mod tests {
12181218
fn parse_with_python_client(input: String) {
12191219
pyo3::prepare_freethreaded_python();
12201220

1221-
println!("{:?}", input);
1221+
println!("{input:?}");
12221222
Python::with_gil(|py| {
12231223
let parser = PyModule::from_code_bound(
12241224
py,

src/metrics/exemplar.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl<S, N: Clone, A: counter::Atomic<N>> CounterWithExemplar<S, N, A> {
128128

129129
/// Get the current value of the [`CounterWithExemplar`] as well as its
130130
/// [`Exemplar`] if any.
131-
pub fn get(&self) -> (N, MappedRwLockReadGuard<Option<Exemplar<S, N>>>) {
131+
pub fn get(&self) -> (N, MappedRwLockReadGuard<'_, Option<Exemplar<S, N>>>) {
132132
let inner = self.inner.read();
133133
let value = inner.counter.get();
134134
let exemplar = RwLockReadGuard::map(inner, |inner| &inner.exemplar);
@@ -143,7 +143,7 @@ impl<S, N: Clone, A: counter::Atomic<N>> CounterWithExemplar<S, N, A> {
143143
/// The caller of this function has to uphold the property of an Open
144144
/// Metrics counter namely that the value is monotonically increasing, i.e.
145145
/// either stays the same or increases.
146-
pub fn inner(&self) -> MappedRwLockReadGuard<A> {
146+
pub fn inner(&self) -> MappedRwLockReadGuard<'_, A> {
147147
RwLockReadGuard::map(self.inner.read(), |inner| inner.counter.inner())
148148
}
149149
}
@@ -261,7 +261,7 @@ impl<S> HistogramWithExemplars<S> {
261261
}
262262
}
263263

264-
pub(crate) fn inner(&self) -> RwLockReadGuard<HistogramWithExemplarsInner<S>> {
264+
pub(crate) fn inner(&self) -> RwLockReadGuard<'_, HistogramWithExemplarsInner<S>> {
265265
self.inner.read()
266266
}
267267
}

src/metrics/family.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ impl<S: Clone + std::hash::Hash + Eq, M, C: MetricConstructor<M>> Family<S, M, C
263263
/// NB: This method can cause deadlocks if multiple metrics within this family are read at
264264
/// once. Use [`Family::get_or_create_owned()`] if you would like to avoid this by cloning the
265265
/// metric `M`.
266-
pub fn get_or_create(&self, label_set: &S) -> MappedRwLockReadGuard<M> {
266+
pub fn get_or_create(&self, label_set: &S) -> MappedRwLockReadGuard<'_, M> {
267267
if let Some(metric) = self.get(label_set) {
268268
return metric;
269269
}
@@ -296,7 +296,7 @@ impl<S: Clone + std::hash::Hash + Eq, M, C: MetricConstructor<M>> Family<S, M, C
296296
/// metric.inc();
297297
/// };
298298
/// ```
299-
pub fn get(&self, label_set: &S) -> Option<MappedRwLockReadGuard<M>> {
299+
pub fn get(&self, label_set: &S) -> Option<MappedRwLockReadGuard<'_, M>> {
300300
RwLockReadGuard::try_map(self.metrics.read(), |metrics| metrics.get(label_set)).ok()
301301
}
302302

@@ -341,7 +341,7 @@ impl<S: Clone + std::hash::Hash + Eq, M, C: MetricConstructor<M>> Family<S, M, C
341341
self.metrics.write().clear()
342342
}
343343

344-
pub(crate) fn read(&self) -> RwLockReadGuard<HashMap<S, M>> {
344+
pub(crate) fn read(&self) -> RwLockReadGuard<'_, HashMap<S, M>> {
345345
self.metrics.read()
346346
}
347347
}

0 commit comments

Comments
 (0)