Struct cfg_rs::PredefinedConfigurationBuilder [−][src]
pub struct PredefinedConfigurationBuilder { /* fields omitted */ }Expand description
Predefined Configuration Builder. See init for details.
Implementations
Set environment prefix, default value if CFG.
By default, following environment variables will be loaded in to configuration.
Environment Variable Regex Pattern: CFG_[0-9a-zA-Z]+
These are some predefined environment variables:
CFG_ENV_PREFIX=CFGCFG_APP_NAME=appCFG_APP_DIR=CFG_APP_PROFILE=
You can change CFG to other prefix by this method.
Set config file profile.
Set config into configuration by programming, or from command line arguments.
Set source from cargo build env. Macro init_cargo_env will collect
all CARGO_PKG_* env variables, and CARGO_BIN_NAME into configuration.
Usage
use cfg_rs::*;
// Generate fn init_cargo_env().
init_cargo_env!();
let c = Configuration::with_predefined_builder()
.set_cargo_env(init_cargo_env())
.init()
.unwrap();Initialize configuration by multiple predefined sources.
Predefined Sources.
- Cargo Package Env Variables (Must be explicitly set by set_cargo_env).
- Customized by Programming or Commandline Args.1
- Random Value (Auto enabled with feature
rand). - Environment Variable with Prefix
CFG, referto set_prefix_env for details.1 - Profiled File Source with Path,
${app.dir}/${app.name}-${app.profile}.EXT. EXT: toml, json, yaml.2 - File Source with Path,
${app.dir}/${app.name}.EXT. EXT: toml, json, yaml.2 - Customized Source Can be Registered by register_source.
Crate Feature
- Feature
randto enable random value source. - Feature
tomlto enable toml supports. - Feature
yamlto enable yaml supports. - Feature
jsonto enable json supports.
Always be enabled. ↩
See Supported File Formats for details. ↩