Skip to content

Commit

Permalink
Add Config::with_merged()
Browse files Browse the repository at this point in the history
This patch adds a builder-pattern version of Config::merge(), which can
be used for method-chain-building Config objects.

Signed-off-by: Matthias Beyer <[email protected]>
  • Loading branch information
matthiasbeyer committed Mar 16, 2021
1 parent fb33478 commit f8cbf85
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,28 @@ impl Config {
self.refresh()
}

/// Merge in a configuration property source.
pub fn with_merged<T>(mut self, source: T) -> Result<Self>
where
T: 'static,
T: Source + Send + Sync,
{
match self.kind {
ConfigKind::Mutable {
ref mut sources, ..
} => {
sources.push(Box::new(source));
}

ConfigKind::Frozen => {
return Err(ConfigError::Frozen);
}
}

self.refresh()?;
Ok(self)
}

/// Refresh the configuration cache with fresh
/// data from added sources.
///
Expand Down

0 comments on commit f8cbf85

Please sign in to comment.