Skip to content

Commit

Permalink
feat(encoding)!: Collector does not consume DescriptorEncoder
Browse files Browse the repository at this point in the history
see #135.

this adjusts the parameter of `encode()` so that it only mutably borrows
the encoder.

Signed-off-by: katelyn martin <[email protected]>
  • Loading branch information
cratelyn committed Nov 18, 2024
1 parent 1ba9526 commit 476bf83
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ use crate::encoding::DescriptorEncoder;
/// ```
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>;
}
2 changes: 1 addition & 1 deletion src/encoding/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 476bf83

Please sign in to comment.