From 7d99951424002920a632dae277ec8f93936b8931 Mon Sep 17 00:00:00 2001 From: katelyn martin Date: Tue, 15 Oct 2024 00:00:00 +0000 Subject: [PATCH] feat(encoding)!: `EncodeExemplarValue` does not consume `ExemplarValueEncoder` see #135. this adjusts the parameter of `encode()` so that it only mutably borrows the encoder. Signed-off-by: katelyn martin --- src/encoding.rs | 10 +++++----- src/encoding/protobuf.rs | 5 ++--- src/encoding/text.rs | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/encoding.rs b/src/encoding.rs index 41af4578..43b608d9 100644 --- a/src/encoding.rs +++ b/src/encoding.rs @@ -691,29 +691,29 @@ impl<'a> CounterValueEncoder<'a> { /// An encodable exemplar value. pub trait EncodeExemplarValue { /// Encode the given instance in the OpenMetrics text encoding. - fn encode(&self, encoder: ExemplarValueEncoder) -> Result<(), std::fmt::Error>; + fn encode(&self, encoder: &mut ExemplarValueEncoder) -> Result<(), std::fmt::Error>; } impl EncodeExemplarValue for f64 { - fn encode(&self, mut encoder: ExemplarValueEncoder) -> Result<(), std::fmt::Error> { + fn encode(&self, encoder: &mut ExemplarValueEncoder) -> Result<(), std::fmt::Error> { encoder.encode(*self) } } impl EncodeExemplarValue for u64 { - fn encode(&self, mut encoder: ExemplarValueEncoder) -> Result<(), std::fmt::Error> { + fn encode(&self, encoder: &mut ExemplarValueEncoder) -> Result<(), std::fmt::Error> { encoder.encode(*self as f64) } } impl EncodeExemplarValue for f32 { - fn encode(&self, mut encoder: ExemplarValueEncoder) -> Result<(), std::fmt::Error> { + fn encode(&self, encoder: &mut ExemplarValueEncoder) -> Result<(), std::fmt::Error> { encoder.encode(*self as f64) } } impl EncodeExemplarValue for u32 { - fn encode(&self, mut encoder: ExemplarValueEncoder) -> Result<(), std::fmt::Error> { + fn encode(&self, encoder: &mut ExemplarValueEncoder) -> Result<(), std::fmt::Error> { encoder.encode(*self as f64) } } diff --git a/src/encoding/protobuf.rs b/src/encoding/protobuf.rs index 3d8c2de7..de34ee31 100644 --- a/src/encoding/protobuf.rs +++ b/src/encoding/protobuf.rs @@ -294,9 +294,8 @@ impl TryFrom<&Exemplar> fn try_from(exemplar: &Exemplar) -> Result { let mut value = f64::default(); - exemplar - .value - .encode(ExemplarValueEncoder { value: &mut value }.into())?; + let mut encoder = ExemplarValueEncoder { value: &mut value }.into(); + exemplar.value.encode(&mut encoder)?; let mut labels = vec![]; let mut encoder = LabelSetEncoder { diff --git a/src/encoding/text.rs b/src/encoding/text.rs index aaac9cc5..e6aa5237 100644 --- a/src/encoding/text.rs +++ b/src/encoding/text.rs @@ -455,7 +455,7 @@ impl<'a> MetricEncoder<'a> { .encode(&mut LabelSetEncoder::new(self.writer).into())?; self.writer.write_str("} ")?; exemplar.value.encode( - ExemplarValueEncoder { + &mut ExemplarValueEncoder { writer: self.writer, } .into(),