Skip to content

Commit 53d02ba

Browse files
committed
Fix missing trait implementations for value encode.
Fixes #172. Signed-off-by: Orne Brocaar <[email protected]>
1 parent 23c31bd commit 53d02ba

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/encoding.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,18 @@ impl EncodeGaugeValue for f64 {
500500
}
501501
}
502502

503+
impl EncodeGaugeValue for i32 {
504+
fn encode(&self, encoder: &mut GaugeValueEncoder) -> Result<(), std::fmt::Error> {
505+
encoder.encode_i64(*self as i64)
506+
}
507+
}
508+
509+
impl EncodeGaugeValue for f32 {
510+
fn encode(&self, encoder: &mut GaugeValueEncoder) -> Result<(), std::fmt::Error> {
511+
encoder.encode_f64(*self as f64)
512+
}
513+
}
514+
503515
/// Encoder for a gauge value.
504516
#[derive(Debug)]
505517
pub struct GaugeValueEncoder<'a>(GaugeValueEncoderInner<'a>);
@@ -552,6 +564,18 @@ impl EncodeCounterValue for f64 {
552564
}
553565
}
554566

567+
impl EncodeCounterValue for u32 {
568+
fn encode(&self, encoder: &mut CounterValueEncoder) -> Result<(), std::fmt::Error> {
569+
encoder.encode_u64(*self as u64)
570+
}
571+
}
572+
573+
impl EncodeCounterValue for f32 {
574+
fn encode(&self, encoder: &mut CounterValueEncoder) -> Result<(), std::fmt::Error> {
575+
encoder.encode_f64(*self as f64)
576+
}
577+
}
578+
555579
/// Encoder for a counter value.
556580
#[derive(Debug)]
557581
pub struct CounterValueEncoder<'a>(CounterValueEncoderInner<'a>);
@@ -591,6 +615,18 @@ impl EncodeExemplarValue for u64 {
591615
}
592616
}
593617

618+
impl EncodeExemplarValue for f32 {
619+
fn encode(&self, mut encoder: ExemplarValueEncoder) -> Result<(), std::fmt::Error> {
620+
encoder.encode(*self as f64)
621+
}
622+
}
623+
624+
impl EncodeExemplarValue for u32 {
625+
fn encode(&self, mut encoder: ExemplarValueEncoder) -> Result<(), std::fmt::Error> {
626+
encoder.encode(*self as f64)
627+
}
628+
}
629+
594630
impl<'a> From<text::CounterValueEncoder<'a>> for CounterValueEncoder<'a> {
595631
fn from(e: text::CounterValueEncoder<'a>) -> Self {
596632
CounterValueEncoder(CounterValueEncoderInner::Text(e))

0 commit comments

Comments
 (0)