Struct cfg_rs::Configuration [−][src]
pub struct Configuration { /* fields omitted */ }Expand description
Configuration Instance, See Examples, How to Initialize Configuration for details.
Implementations
Create an empty Configuration.
If you want to use predefined sources, please try Configuration::with_predefined or Configuration::with_predefined_builder.
Register key value manually.
Register all env variables with prefix, default prefix is CFG.
prefix- Env variable prefix.
If prefix is CFG, then all env variables with pattern CFG_* will be added into configuration.
Examples:
CFG_APP_NAME=>app.nameCFG_APP_0_NAME=>app[0].name
pub fn register_file<P: Into<PathBuf>>(
self,
path: P,
required: bool
) -> Result<Self, ConfigError>
pub fn register_file<P: Into<PathBuf>>(
self,
path: P,
required: bool
) -> Result<Self, ConfigError>
Register file source, this method uses file extension1 to choose how to parsing configuration.
path- Config file path.required- Whether config file must exist.
See Supported File Formats for details.
cfg-rsdoes not enable any file format by default, please enable specific features when use this method. ↩
This is supported on crate feature rand only.
rand only.Register random value source, must enable feature rand.
Supported integer types:
- random.u8
- random.u16
- random.u32
- random.u64
- random.u128
- random.usize
- random.i8
- random.i16
- random.i32
- random.i64
- random.i128
- random.isize
pub fn register_source<L: ConfigSource + 'static>(
self,
loader: L
) -> Result<Self, ConfigError>
pub fn register_source<L: ConfigSource + 'static>(
self,
loader: L
) -> Result<Self, ConfigError>
Register customized source, see How to Initialize Configuration, ConfigSource for details.
Refresh all RefValues without change Configuration itself.
Refresh all RefValues and Configuration itself.
Get config from configuration by key, see ConfigKey for the key’s pattern details.
key- Config Key. Key examples:
cfg.v1cfg.v2[0]cfg.v3[0][1]cfg.v4.keycfg.v5.arr[0]
Get config from configuration by key, otherwise return default. See ConfigKey for the key’s pattern details.
key- Config Key.def- If config value is not found, then return def.
Get config with predefined key, which is automatically derived by FromConfig.
Get source names, just for test.
Create predefined sources builder, see init for details.
Create predefined configuration, see init for details.