Skip to content

Commit 319de9b

Browse files
mxindenemschwartz
andauthored
feat(encoding): implement EncodeLabelValue for Option (#141)
Signed-off-by: Evan Schwartz <[email protected]> Co-authored-by: Evan Schwartz <[email protected]>
1 parent 2649447 commit 319de9b

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [0.21.1]
8+
9+
### Added
10+
11+
- Implement `EncodeLabelValue` for `Option<T>`.
12+
See [PR 137].
13+
14+
[PR 137]: https://github.com/prometheus/client_rust/pull/137
15+
716
## [0.21.0]
817

918
### Changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "prometheus-client"
3-
version = "0.21.0"
3+
version = "0.21.1"
44
authors = ["Max Inden <[email protected]>"]
55
edition = "2021"
66
description = "Open Metrics client library allowing users to natively instrument applications."

src/encoding.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,18 @@ impl EncodeLabelValue for f64 {
404404
}
405405
}
406406

407+
impl<T> EncodeLabelValue for Option<T>
408+
where
409+
T: EncodeLabelValue,
410+
{
411+
fn encode(&self, encoder: &mut LabelValueEncoder) -> Result<(), std::fmt::Error> {
412+
match self {
413+
Some(v) => EncodeLabelValue::encode(v, encoder),
414+
None => EncodeLabelValue::encode(&"", encoder),
415+
}
416+
}
417+
}
418+
407419
macro_rules! impl_encode_label_value_for_integer {
408420
($($t:ident),*) => {$(
409421
impl EncodeLabelValue for $t {

0 commit comments

Comments
 (0)