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:

  1. CFG_APP_NAME => app.name
  2. CFG_APP_0_NAME => app[0].name

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.


  1. cfg-rs does not enable any file format by default, please enable specific features when use this method. 

This is supported on crate feature 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

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:
  1. cfg.v1
  2. cfg.v2[0]
  3. cfg.v3[0][1]
  4. cfg.v4.key
  5. cfg.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.

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.