Skip to content

Commit b886c4e

Browse files
committed
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>
1 parent a9ce652 commit b886c4e

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/config.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,28 @@ impl Config {
7878
self.refresh()
7979
}
8080

81+
/// Merge in a configuration property source.
82+
pub fn with_merged<T>(mut self, source: T) -> Result<Self>
83+
where
84+
T: 'static,
85+
T: Source + Send + Sync,
86+
{
87+
match self.kind {
88+
ConfigKind::Mutable {
89+
ref mut sources, ..
90+
} => {
91+
sources.push(Box::new(source));
92+
}
93+
94+
ConfigKind::Frozen => {
95+
return Err(ConfigError::Frozen);
96+
}
97+
}
98+
99+
self.refresh()?;
100+
Ok(self)
101+
}
102+
81103
/// Refresh the configuration cache with fresh
82104
/// data from added sources.
83105
///

0 commit comments

Comments
 (0)