From 9ff37dbf691cfa680b2418972681afd4a37eb721 Mon Sep 17 00:00:00 2001 From: Evan Schwartz <3262610+emschwartz@users.noreply.github.com> Date: Fri, 21 Apr 2023 15:16:25 +0200 Subject: [PATCH] Impl EncodeLabelValue for Option Signed-off-by: Evan Schwartz <3262610+emschwartz@users.noreply.github.com> --- src/encoding.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 {