diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a8f53b4..5394e8e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.21.1] + +### Added + +- Implement `EncodeLabelValue` for `Option`. + See [PR 137]. + +[PR 137]: https://github.com/prometheus/client_rust/pull/137 + ## [0.21.0] ### Changed diff --git a/Cargo.toml b/Cargo.toml index 627f361e..be843a9f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "prometheus-client" -version = "0.21.0" +version = "0.21.1" authors = ["Max Inden "] edition = "2021" description = "Open Metrics client library allowing users to natively instrument applications." diff --git a/src/encoding.rs b/src/encoding.rs index b59f2450..ac758e61 100644 --- a/src/encoding.rs +++ b/src/encoding.rs @@ -404,6 +404,18 @@ impl EncodeLabelValue for f64 { } } +impl EncodeLabelValue for Option +where + T: EncodeLabelValue, +{ + fn encode(&self, encoder: &mut LabelValueEncoder) -> Result<(), std::fmt::Error> { + match self { + Some(v) => EncodeLabelValue::encode(v, encoder), + None => EncodeLabelValue::encode(&"", encoder), + } + } +} + macro_rules! impl_encode_label_value_for_integer { ($($t:ident),*) => {$( impl EncodeLabelValue for $t {