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=CFG
  • CFG_APP_NAME=app
  • CFG_APP_DIR=
  • CFG_APP_PROFILE=

You can change CFG to other prefix by this method.

Set config file directory.

Set config file name.

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.

  1. Cargo Package Env Variables (Must be explicitly set by set_cargo_env).
  2. Customized by Programming or Commandline Args.1
  3. Random Value (Auto enabled with feature rand).
  4. Environment Variable with Prefix CFG, referto set_prefix_env for details.1
  5. Profiled File Source with Path, ${app.dir}/${app.name}-${app.profile}.EXT. EXT: toml, json, yaml.2
  6. File Source with Path, ${app.dir}/${app.name}.EXT. EXT: toml, json, yaml.2
  7. Customized Source Can be Registered by register_source.

Crate Feature

  • Feature rand to enable random value source.
  • Feature toml to enable toml supports.
  • Feature yaml to enable yaml supports.
  • Feature json to enable json supports.

  1. Always be enabled. 

  2. See Supported File Formats for details. 

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.