pub struct Config<Cfg> { /* private fields */ }Expand description
Builder that collects configuration Sources and merges them.
Config<Cfg> is generic over a target configuration type Cfg. When
Cfg implements serde::Deserialize and Combine, Config can
deserialize the merged configuration into the typed value using
extract().
Implementations§
Source§impl<Cfg> Config<Cfg>where
Cfg: DeserializeOwned + Combine,
impl<Cfg> Config<Cfg>where
Cfg: DeserializeOwned + Combine,
pub fn new() -> Self
pub fn with_source(self, source: impl Source + 'static) -> Self
pub fn with_sources<I, S>(self, sources: I) -> Selfwhere
S: Source + 'static,
I: IntoIterator<Item = S>,
Sourcepub fn set_value<Fmt>(
&self,
path: &str,
value: impl Into<Value>,
in_config_path: impl AsRef<Path>,
) -> Result<(), WriteError>where
Fmt: 'static + Format,
pub fn set_value<Fmt>(
&self,
path: &str,
value: impl Into<Value>,
in_config_path: impl AsRef<Path>,
) -> Result<(), WriteError>where
Fmt: 'static + Format,
Sets the value under specified path creating new or merging it into existing config file
pub fn unset_value<Fmt>(
&self,
path: &str,
in_config_path: &Path,
) -> Result<Option<Value>, WriteError>where
Fmt: Format,
Source§impl<Cfg: DeserializeOwned + JsonSchema + Combine + Validate> Config<Cfg>
impl<Cfg: DeserializeOwned + JsonSchema + Combine + Validate> Config<Cfg>
Sourcepub fn with_deprecation_clb(
self,
clb: impl Fn(&[&str], Option<&str>, Option<&str>) + 'static,
) -> Self
pub fn with_deprecation_clb( self, clb: impl Fn(&[&str], Option<&str>, Option<&str>) + 'static, ) -> Self
Provide a callback used to report use of deprecated fields. The callback will receive full path of the property and an optional deprecation reason.
Sourcepub fn extract(&self) -> Result<Cfg, ReadError>
pub fn extract(&self) -> Result<Cfg, ReadError>
Deserializes the marged config into the config type and performs deprecation checks and validation.
Sourcepub fn get_value(
&self,
path: &str,
with_defaults: bool,
) -> Result<Option<Value>, ReadError>
pub fn get_value( &self, path: &str, with_defaults: bool, ) -> Result<Option<Value>, ReadError>
Returns value under specified path
Sourcepub fn json_schema(&self) -> Schema
pub fn json_schema(&self) -> Schema
Returns JSON Schema describing the config type
Sourcepub fn complete_path(&self, prefix: &str) -> Vec<String>
pub fn complete_path(&self, prefix: &str) -> Vec<String>
Given a prefix like some.va would return possible completions, e.g.
some.value and some.validator