From e701e0071910169e4e21d3d5331a18aaecedb78b Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 20 Nov 2020 17:51:40 +0100 Subject: 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 --- src/config.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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(mut self, source: T) -> Result + 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. /// -- cgit v1.2.3