From 63980d97287db845e125366250e82b37118b04b4 Mon Sep 17 00:00:00 2001 From: Taylor Beever Date: Mon, 1 Apr 2024 11:48:51 -0600 Subject: [PATCH] Add convenience function set_if on ClientConfig --- src/config.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/config.rs b/src/config.rs index 296d9f867..c5988f647 100644 --- a/src/config.rs +++ b/src/config.rs @@ -208,6 +208,20 @@ impl ClientConfig { self.conf_map.insert(key.into(), value.into()); self } + /// Sets a parameter in the configuration if the value is Some. + /// + /// If there is an existing value for `key` in the configuration and value is Some, it is + /// overridden with the new `Some(value)`. + pub fn set_if(&mut self, key: K, value: Option) -> &mut ClientConfig + where + K: Into, + V: Into, + { + match value { + Some(value) => self.set(key, value), + None => self, + } + } /// Removes a parameter from the configuration. pub fn remove<'a>(&'a mut self, key: &str) -> &'a mut ClientConfig {