diff --git a/Cargo.toml b/Cargo.toml index 5514ab6..18dd395 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,6 +29,7 @@ prost-types = { version = "0.12.0", optional = true } async-std = { version = "1", features = ["attributes"] } axum = "0.7" criterion = "0.5" +futures = "0.3" http-types = "2" pyo3 = "0.22" quickcheck = "1" diff --git a/examples/hyper.rs b/examples/hyper.rs index 82ee121..bbab005 100644 --- a/examples/hyper.rs +++ b/examples/hyper.rs @@ -1,3 +1,4 @@ +use futures::future::BoxFuture; use http_body_util::{combinators, BodyExt, Full}; use hyper::{ body::{Bytes, Incoming}, @@ -8,10 +9,8 @@ use hyper::{ use hyper_util::rt::TokioIo; use prometheus_client::{encoding::text::encode, metrics::counter::Counter, registry::Registry}; use std::{ - future::Future, io, net::{IpAddr, Ipv4Addr, SocketAddr}, - pin::Pin, sync::Arc, }; use tokio::{ @@ -69,8 +68,7 @@ type BoxBody = combinators::BoxBody; /// This function returns a HTTP handler (i.e. another function) pub fn make_handler( registry: Arc, -) -> impl Fn(Request) -> Pin>> + Send>> -{ +) -> impl Fn(Request) -> BoxFuture<'static, io::Result>> { // This closure accepts a request and responds with the OpenMetrics encoding of our metrics. move |_req: Request| { let reg = registry.clone(); diff --git a/src/encoding.rs b/src/encoding.rs index 7f77efa..9b2e497 100644 --- a/src/encoding.rs +++ b/src/encoding.rs @@ -230,7 +230,7 @@ impl<'a> From> for LabelSetEncoder<'a> { } } -impl<'a> LabelSetEncoder<'a> { +impl LabelSetEncoder<'_> { /// Encode the given label. pub fn encode_label(&mut self) -> LabelEncoder { for_both_mut!(self, LabelSetEncoderInner, e, e.encode_label().into()) @@ -271,7 +271,7 @@ impl<'a> From> for LabelEncoder<'a> { } } -impl<'a> LabelEncoder<'a> { +impl LabelEncoder<'_> { /// Encode a label. pub fn encode_label_key(&mut self) -> Result { for_both_mut!( @@ -313,7 +313,7 @@ impl<'a> From> for LabelKeyEncoder<'a> { } } -impl<'a> std::fmt::Write for LabelKeyEncoder<'a> { +impl std::fmt::Write for LabelKeyEncoder<'_> { fn write_str(&mut self, s: &str) -> std::fmt::Result { for_both_mut!(self, LabelKeyEncoderInner, e, e.write_str(s)) } @@ -390,7 +390,7 @@ impl EncodeLabelKey for String { } } -impl<'a> EncodeLabelKey for Cow<'a, str> { +impl EncodeLabelKey for Cow<'_, str> { fn encode(&self, encoder: &mut LabelKeyEncoder) -> Result<(), std::fmt::Error> { EncodeLabelKey::encode(&self.as_ref(), encoder) } @@ -453,14 +453,14 @@ enum LabelValueEncoderInner<'a> { Protobuf(protobuf::LabelValueEncoder<'a>), } -impl<'a> LabelValueEncoder<'a> { +impl LabelValueEncoder<'_> { /// Finish encoding the label value. pub fn finish(self) -> Result<(), std::fmt::Error> { for_both!(self, LabelValueEncoderInner, e, e.finish()) } } -impl<'a> std::fmt::Write for LabelValueEncoder<'a> { +impl std::fmt::Write for LabelValueEncoder<'_> { fn write_str(&mut self, s: &str) -> std::fmt::Result { for_both_mut!(self, LabelValueEncoderInner, e, e.write_str(s)) } @@ -485,7 +485,7 @@ impl EncodeLabelValue for &String { } } -impl<'a> EncodeLabelValue for Cow<'a, str> { +impl EncodeLabelValue for Cow<'_, str> { fn encode(&self, encoder: &mut LabelValueEncoder) -> Result<(), std::fmt::Error> { EncodeLabelValue::encode(&self.as_ref(), encoder) } @@ -610,7 +610,7 @@ enum GaugeValueEncoderInner<'a> { Protobuf(protobuf::GaugeValueEncoder<'a>), } -impl<'a> GaugeValueEncoder<'a> { +impl GaugeValueEncoder<'_> { fn encode_u32(&mut self, v: u32) -> Result<(), std::fmt::Error> { for_both_mut!(self, GaugeValueEncoderInner, e, e.encode_u32(v)) } @@ -678,7 +678,7 @@ enum CounterValueEncoderInner<'a> { Protobuf(protobuf::CounterValueEncoder<'a>), } -impl<'a> CounterValueEncoder<'a> { +impl CounterValueEncoder<'_> { fn encode_f64(&mut self, v: f64) -> Result<(), std::fmt::Error> { for_both_mut!(self, CounterValueEncoderInner, e, e.encode_f64(v)) } @@ -742,7 +742,7 @@ enum ExemplarValueEncoderInner<'a> { Protobuf(protobuf::ExemplarValueEncoder<'a>), } -impl<'a> ExemplarValueEncoder<'a> { +impl ExemplarValueEncoder<'_> { fn encode(&mut self, v: f64) -> Result<(), std::fmt::Error> { for_both_mut!(self, ExemplarValueEncoderInner, e, e.encode(v)) } diff --git a/src/encoding/protobuf.rs b/src/encoding/protobuf.rs index 095a3db..5ec54c9 100644 --- a/src/encoding/protobuf.rs +++ b/src/encoding/protobuf.rs @@ -322,7 +322,7 @@ pub(crate) struct GaugeValueEncoder<'a> { value: &'a mut openmetrics_data_model::gauge_value::Value, } -impl<'a> GaugeValueEncoder<'a> { +impl GaugeValueEncoder<'_> { pub fn encode_u32(&mut self, v: u32) -> Result<(), std::fmt::Error> { self.encode_i64(v as i64) } @@ -343,7 +343,7 @@ pub(crate) struct ExemplarValueEncoder<'a> { value: &'a mut f64, } -impl<'a> ExemplarValueEncoder<'a> { +impl ExemplarValueEncoder<'_> { pub fn encode(&mut self, v: f64) -> Result<(), std::fmt::Error> { *self.value = v; Ok(()) @@ -364,7 +364,7 @@ pub(crate) struct CounterValueEncoder<'a> { value: &'a mut openmetrics_data_model::counter_value::Total, } -impl<'a> CounterValueEncoder<'a> { +impl CounterValueEncoder<'_> { pub fn encode_f64(&mut self, v: f64) -> Result<(), std::fmt::Error> { *self.value = openmetrics_data_model::counter_value::Total::DoubleValue(v); Ok(()) @@ -381,7 +381,7 @@ pub(crate) struct LabelSetEncoder<'a> { labels: &'a mut Vec, } -impl<'a> LabelSetEncoder<'a> { +impl LabelSetEncoder<'_> { pub fn encode_label(&mut self) -> LabelEncoder { LabelEncoder { labels: self.labels, @@ -394,7 +394,7 @@ pub(crate) struct LabelEncoder<'a> { labels: &'a mut Vec, } -impl<'a> LabelEncoder<'a> { +impl LabelEncoder<'_> { pub fn encode_label_key(&mut self) -> Result { self.labels.push(openmetrics_data_model::Label::default()); @@ -409,7 +409,7 @@ pub(crate) struct LabelKeyEncoder<'a> { label: &'a mut openmetrics_data_model::Label, } -impl<'a> std::fmt::Write for LabelKeyEncoder<'a> { +impl std::fmt::Write for LabelKeyEncoder<'_> { fn write_str(&mut self, s: &str) -> std::fmt::Result { self.label.name.write_str(s) } @@ -428,13 +428,13 @@ pub(crate) struct LabelValueEncoder<'a> { label_value: &'a mut String, } -impl<'a> LabelValueEncoder<'a> { +impl LabelValueEncoder<'_> { pub fn finish(self) -> Result<(), std::fmt::Error> { Ok(()) } } -impl<'a> std::fmt::Write for LabelValueEncoder<'a> { +impl std::fmt::Write for LabelValueEncoder<'_> { fn write_str(&mut self, s: &str) -> std::fmt::Result { self.label_value.write_str(s) } diff --git a/src/encoding/text.rs b/src/encoding/text.rs index 4946fe3..8f3c63d 100644 --- a/src/encoding/text.rs +++ b/src/encoding/text.rs @@ -188,7 +188,7 @@ pub(crate) struct DescriptorEncoder<'a> { labels: &'a [(Cow<'static, str>, Cow<'static, str>)], } -impl<'a> std::fmt::Debug for DescriptorEncoder<'a> { +impl std::fmt::Debug for DescriptorEncoder<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("DescriptorEncoder").finish() } @@ -293,7 +293,7 @@ pub(crate) struct MetricEncoder<'a> { family_labels: Option<&'a dyn super::EncodeLabelSet>, } -impl<'a> std::fmt::Debug for MetricEncoder<'a> { +impl std::fmt::Debug for MetricEncoder<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let mut labels = String::new(); if let Some(l) = self.family_labels { @@ -310,7 +310,7 @@ impl<'a> std::fmt::Debug for MetricEncoder<'a> { } } -impl<'a> MetricEncoder<'a> { +impl MetricEncoder<'_> { pub fn encode_counter< S: EncodeLabelSet, CounterValue: super::EncodeCounterValue, @@ -555,13 +555,13 @@ pub(crate) struct CounterValueEncoder<'a> { writer: &'a mut dyn Write, } -impl<'a> std::fmt::Debug for CounterValueEncoder<'a> { +impl std::fmt::Debug for CounterValueEncoder<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("CounterValueEncoder").finish() } } -impl<'a> CounterValueEncoder<'a> { +impl CounterValueEncoder<'_> { pub fn encode_f64(&mut self, v: f64) -> Result<(), std::fmt::Error> { self.writer.write_str(" ")?; self.writer.write_str(dtoa::Buffer::new().format(v))?; @@ -579,13 +579,13 @@ pub(crate) struct GaugeValueEncoder<'a> { writer: &'a mut dyn Write, } -impl<'a> std::fmt::Debug for GaugeValueEncoder<'a> { +impl std::fmt::Debug for GaugeValueEncoder<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("GaugeValueEncoder").finish() } } -impl<'a> GaugeValueEncoder<'a> { +impl GaugeValueEncoder<'_> { pub fn encode_u32(&mut self, v: u32) -> Result<(), std::fmt::Error> { self.writer.write_str(" ")?; self.writer.write_str(itoa::Buffer::new().format(v))?; @@ -609,13 +609,13 @@ pub(crate) struct ExemplarValueEncoder<'a> { writer: &'a mut dyn Write, } -impl<'a> std::fmt::Debug for ExemplarValueEncoder<'a> { +impl std::fmt::Debug for ExemplarValueEncoder<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("ExemplarValueEncoder").finish() } } -impl<'a> ExemplarValueEncoder<'a> { +impl ExemplarValueEncoder<'_> { pub fn encode(&mut self, v: f64) -> Result<(), std::fmt::Error> { self.writer.write_str(dtoa::Buffer::new().format(v)) } @@ -626,7 +626,7 @@ pub(crate) struct LabelSetEncoder<'a> { first: bool, } -impl<'a> std::fmt::Debug for LabelSetEncoder<'a> { +impl std::fmt::Debug for LabelSetEncoder<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("LabelSetEncoder") .field("first", &self.first) @@ -657,7 +657,7 @@ pub(crate) struct LabelEncoder<'a> { first: bool, } -impl<'a> std::fmt::Debug for LabelEncoder<'a> { +impl std::fmt::Debug for LabelEncoder<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("LabelEncoder") .field("first", &self.first) @@ -665,7 +665,7 @@ impl<'a> std::fmt::Debug for LabelEncoder<'a> { } } -impl<'a> LabelEncoder<'a> { +impl LabelEncoder<'_> { pub fn encode_label_key(&mut self) -> Result { if !self.first { self.writer.write_str(",")?; @@ -680,7 +680,7 @@ pub(crate) struct LabelKeyEncoder<'a> { writer: &'a mut dyn Write, } -impl<'a> std::fmt::Debug for LabelKeyEncoder<'a> { +impl std::fmt::Debug for LabelKeyEncoder<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("LabelKeyEncoder").finish() } @@ -695,7 +695,7 @@ impl<'a> LabelKeyEncoder<'a> { } } -impl<'a> std::fmt::Write for LabelKeyEncoder<'a> { +impl std::fmt::Write for LabelKeyEncoder<'_> { fn write_str(&mut self, s: &str) -> std::fmt::Result { self.writer.write_str(s) } @@ -705,19 +705,19 @@ pub(crate) struct LabelValueEncoder<'a> { writer: &'a mut dyn Write, } -impl<'a> std::fmt::Debug for LabelValueEncoder<'a> { +impl std::fmt::Debug for LabelValueEncoder<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("LabelValueEncoder").finish() } } -impl<'a> LabelValueEncoder<'a> { +impl LabelValueEncoder<'_> { pub fn finish(self) -> Result<(), std::fmt::Error> { self.writer.write_str("\"") } } -impl<'a> std::fmt::Write for LabelValueEncoder<'a> { +impl std::fmt::Write for LabelValueEncoder<'_> { fn write_str(&mut self, s: &str) -> std::fmt::Result { self.writer.write_str(s) }