summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRafael Saraiva Figueiredo <rafael.saraiva132@gmail.com>2022-03-18 16:21:18 +0000
committerMatthias Beyer <mail@beyermatthias.de>2022-03-22 07:56:34 +0100
commitbe7afe91c988169b217971a169acd89f74e50121 (patch)
tree0aabc3371f36a434c5c7c4763b510b8753b602db /src
parentd2d356142430723bbfed102cf8dc41e6fd0aa84e (diff)
Add ConfigBuilder::set_override_option()
This patch adds ConfigBuilder::set_override_option() to override a setting from an Option<_>. Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'src')
-rw-r--r--src/builder.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/builder.rs b/src/builder.rs
index 018713c..ee83bfe 100644
--- a/src/builder.rs
+++ b/src/builder.rs
@@ -173,6 +173,26 @@ impl<St: BuilderState> ConfigBuilder<St> {
.insert(Expression::from_str(key.as_ref())?, value.into());
Ok(self)
}
+
+ /// Sets an override if value is Some(_)
+ ///
+ /// This function sets an overwrite value if Some(_) is passed. If None is passed, this function does nothing.
+ /// It will not be altered by any default, [`Source`] nor [`AsyncSource`]
+ ///
+ /// # Errors
+ ///
+ /// Fails if `Expression::from_str(key)` fails.
+ pub fn set_override_option<S, T>(mut self, key: S, value: Option<T>) -> Result<Self>
+ where
+ S: AsRef<str>,
+ T: Into<Value>,
+ {
+ if let Some(value) = value {
+ self.overrides
+ .insert(Expression::from_str(key.as_ref())?, value.into());
+ }
+ Ok(self)
+ }
}
impl ConfigBuilder<DefaultState> {