diff --git a/src/collector.rs b/src/collector.rs index 66270c4..eb37751 100644 --- a/src/collector.rs +++ b/src/collector.rs @@ -22,20 +22,20 @@ use crate::encoding::DescriptorEncoder; /// struct MyCollector {} /// /// impl Collector for MyCollector { -/// fn encode(&self, mut encoder: DescriptorEncoder) -> Result<(), std::fmt::Error> { +/// fn encode(&self, encoder: &mut DescriptorEncoder) -> Result<(), std::fmt::Error> { /// let counter = ConstCounter::new(42u64); -/// let metric_encoder = encoder.encode_descriptor( +/// let mut metric_encoder = encoder.encode_descriptor( /// "my_counter", /// "some help", /// None, /// counter.metric_type(), /// )?; -/// counter.encode(metric_encoder)?; +/// counter.encode(&mut metric_encoder)?; /// Ok(()) /// } /// } /// ``` pub trait Collector: std::fmt::Debug + Send + Sync + 'static { /// Once the [`Collector`] is registered, this method is called on each scrape. - fn encode(&self, encoder: DescriptorEncoder) -> Result<(), std::fmt::Error>; + fn encode(&self, encoder: &mut DescriptorEncoder) -> Result<(), std::fmt::Error>; } diff --git a/src/encoding/text.rs b/src/encoding/text.rs index ca44aa9..aaac9cc 100644 --- a/src/encoding/text.rs +++ b/src/encoding/text.rs @@ -1077,7 +1077,7 @@ mod tests { impl crate::collector::Collector for Collector { fn encode( &self, - mut encoder: crate::encoding::DescriptorEncoder, + encoder: &mut crate::encoding::DescriptorEncoder, ) -> Result<(), std::fmt::Error> { let counter = crate::metrics::counter::ConstCounter::new(42u64); let mut metric_encoder = encoder.encode_descriptor( diff --git a/src/registry.rs b/src/registry.rs index 77653e2..d1be85a 100644 --- a/src/registry.rs +++ b/src/registry.rs @@ -184,15 +184,15 @@ impl Registry { /// struct MyCollector {} /// /// impl Collector for MyCollector { - /// fn encode(&self, mut encoder: DescriptorEncoder) -> Result<(), std::fmt::Error> { + /// fn encode(&self, encoder: &mut DescriptorEncoder) -> Result<(), std::fmt::Error> { /// let counter = ConstCounter::new(42u64); - /// let metric_encoder = encoder.encode_descriptor( + /// let mut metric_encoder = encoder.encode_descriptor( /// "my_counter", /// "some help", /// None, /// counter.metric_type(), /// )?; - /// counter.encode(metric_encoder)?; + /// counter.encode(&mut metric_encoder)?; /// Ok(()) /// } /// } @@ -300,9 +300,9 @@ impl Registry { } for collector in self.collectors.iter() { - let descriptor_encoder = + let mut descriptor_encoder = encoder.with_prefix_and_labels(self.prefix.as_ref(), &self.labels); - collector.encode(descriptor_encoder)?; + collector.encode(&mut descriptor_encoder)?; } for registry in self.sub_registries.iter() {