Skip to content

Commit

Permalink
Fix missing trait implementations for value encode.
Browse files Browse the repository at this point in the history
Fixes #172.
  • Loading branch information
brocaar committed Oct 28, 2023
1 parent 23c31bd commit 3fd3a1b
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,18 @@ impl EncodeGaugeValue for f64 {
}
}

impl EncodeGaugeValue for i32 {
fn encode(&self, encoder: &mut GaugeValueEncoder) -> Result<(), std::fmt::Error> {
encoder.encode_i64(*self as i64)
}
}

impl EncodeGaugeValue for f32 {
fn encode(&self, encoder: &mut GaugeValueEncoder) -> Result<(), std::fmt::Error> {
encoder.encode_f64(*self as f64)
}
}

/// Encoder for a gauge value.
#[derive(Debug)]
pub struct GaugeValueEncoder<'a>(GaugeValueEncoderInner<'a>);
Expand Down Expand Up @@ -552,6 +564,24 @@ impl EncodeCounterValue for f64 {
}
}

impl EncodeCounterValue for u32 {
fn encode(&self, encoder: &mut CounterValueEncoder) -> Result<(), std::fmt::Error> {
encoder.encode_u64(*self as u64)
}
}

impl EncodeCounterValue for i32 {
fn encode(&self, encoder: &mut CounterValueEncoder) -> Result<(), std::fmt::Error> {
encoder.encode_u64(*self as u64)
}
}

impl EncodeCounterValue for f32 {
fn encode(&self, encoder: &mut CounterValueEncoder) -> Result<(), std::fmt::Error> {
encoder.encode_f64(*self as f64)
}
}

/// Encoder for a counter value.
#[derive(Debug)]
pub struct CounterValueEncoder<'a>(CounterValueEncoderInner<'a>);
Expand Down Expand Up @@ -591,6 +621,18 @@ impl EncodeExemplarValue for u64 {
}
}

impl EncodeExemplarValue for f32 {
fn encode(&self, mut encoder: ExemplarValueEncoder) -> Result<(), std::fmt::Error> {
encoder.encode(*self as f64)
}
}

impl EncodeExemplarValue for u32 {
fn encode(&self, mut encoder: ExemplarValueEncoder) -> Result<(), std::fmt::Error> {
encoder.encode(*self as f64)
}
}

impl<'a> From<text::CounterValueEncoder<'a>> for CounterValueEncoder<'a> {
fn from(e: text::CounterValueEncoder<'a>) -> Self {
CounterValueEncoder(CounterValueEncoderInner::Text(e))
Expand Down

0 comments on commit 3fd3a1b

Please sign in to comment.