diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2021-03-17 17:43:30 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-17 17:43:30 +0100 |
commit | 66e3f7d7b5062afe6f58f92cc5db328198ae93cb (patch) | |
tree | d1dff321708628622f302fd5bee75842c899a1bc | |
parent | a9ce6521d021909c13e52b50c3b26a28edaad65a (diff) | |
parent | b886c4ecf2977ed7015f4ec8284663a4f3aa1082 (diff) |
Merge pull request #166 from matthiasbeyer/builder
Add Config::with_merged()
-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. /// |