Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
`EncodeGaugeValue` would not error when encoding some `u64`s that don't fit
in a `i64`. See [PR 281].

- `EncodeGaugeValue` is implemented for `usize` and `isize`, and
`EncodeCounterValue` is implemented for `usize`. See [PR 282].

[PR 281]: https://github.com/prometheus/client_rust/pull/281
[PR 282]: https://github.com/prometheus/client_rust/pull/282

## [0.24.0]

Expand Down
22 changes: 22 additions & 0 deletions src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,21 @@ impl EncodeGaugeValue for u64 {
}
}

impl EncodeGaugeValue for isize {
fn encode(&self, encoder: &mut GaugeValueEncoder) -> Result<(), std::fmt::Error> {
// Is infallible for 32-bit or 64-bit platforms
encoder.encode_i64(i64::try_from(*self).map_err(|_err| std::fmt::Error)?)
}
}

impl EncodeGaugeValue for usize {
fn encode(&self, encoder: &mut GaugeValueEncoder) -> Result<(), std::fmt::Error> {
// For 32-bit platforms this is infallible, for 64-bit platforms the argument is the same
// as the one for u64 values
encoder.encode_i64(i64::try_from(*self).map_err(|_err| std::fmt::Error)?)
}
}

impl EncodeGaugeValue for f64 {
fn encode(&self, encoder: &mut GaugeValueEncoder) -> Result<(), std::fmt::Error> {
encoder.encode_f64(*self)
Expand Down Expand Up @@ -675,6 +690,13 @@ impl EncodeCounterValue for u64 {
}
}

impl EncodeCounterValue for usize {
fn encode(&self, encoder: &mut CounterValueEncoder) -> Result<(), std::fmt::Error> {
// Is infallible for 32-bit and 64-bit platforms
encoder.encode_u64(u64::try_from(*self).map_err(|_err| std::fmt::Error)?)
}
}

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