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(),