Skip to content

Commit 66e3f7d

Browse files
Merge pull request #166 from matthiasbeyer/builder
Add Config::with_merged()
2 parents a9ce652 + b886c4e commit 66e3f7d

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)