Skip to content

Commit

Permalink
Merge pull request #303 from saraiva132/302-add-set-override-option
Browse files Browse the repository at this point in the history
302-add-set-override-option-combinator
  • Loading branch information
matthiasbeyer authored Mar 22, 2022
2 parents d2d3561 + be7afe9 commit 56c148b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down

0 comments on commit 56c148b

Please sign in to comment.