diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2020-11-20 17:51:40 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2021-03-13 11:29:37 +0100 |
commit | e701e0071910169e4e21d3d5331a18aaecedb78b (patch) | |
tree | 3286a5397b252f2c4a487cfe06940d51884fbe51 | |
parent | 887736dc67740e5316a892bfcb569f62d0fc45da (diff) |
Add Config::with_merged()
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 <mail@beyermatthias.de>
-rw-r--r-- | src/config.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs index 888d8cc..f4d21d5 100644 --- a/src/config.rs +++ b/src/config.rs @@ -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. /// |