From 96796bc35e7cacb1d10e964b249bec3a28e215d8 Mon Sep 17 00:00:00 2001 From: koushiro Date: Sun, 10 Nov 2024 21:13:00 +0800 Subject: [PATCH] feat(encoding): impl EncodeLabelValue for bool Signed-off-by: koushiro --- CHANGELOG.md | 7 ++++++- src/encoding.rs | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c398e073..945d128f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,8 +18,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Implement `Atomic` for `AtomicU64` for gauges. See [PR 226]. -[PR 226]: https://github.com/prometheus/client_rust/pull/198 +- Implement `EnableLabelValue` for `bool`. + See [PR 237] + +[PR 173]: https://github.com/prometheus/client_rust/pull/173 [PR 198]: https://github.com/prometheus/client_rust/pull/198 +[PR 226]: https://github.com/prometheus/client_rust/pull/226 +[PR 237]: https://github.com/prometheus/client_rust/pull/237 ### Added diff --git a/src/encoding.rs b/src/encoding.rs index 6f3f2ef7..9e2acac0 100644 --- a/src/encoding.rs +++ b/src/encoding.rs @@ -537,6 +537,12 @@ where } } +impl EncodeLabelValue for bool { + fn encode(&self, encoder: &mut LabelValueEncoder) -> Result<(), std::fmt::Error> { + encoder.write_str(if *self { "true" } else { "false" }) + } +} + macro_rules! impl_encode_label_value_for_integer { ($($t:ident),*) => {$( impl EncodeLabelValue for $t {