pub struct PredefinedConfigurationBuilder { /* private fields */ }
Expand description
Predefined Configuration Builder. See init for details.
Implementations§
Source§impl PredefinedConfigurationBuilder
impl PredefinedConfigurationBuilder
Sourcepub fn set_prefix_env<K: ToString>(self, prefix: K) -> Self
pub fn set_prefix_env<K: ToString>(self, prefix: K) -> Self
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.
Sourcepub fn set_profile<V: Into<String>>(self, profile: V) -> Self
pub fn set_profile<V: Into<String>>(self, profile: V) -> Self
Set config file profile.
Sourcepub fn set<K: Borrow<str>, V: Into<ConfigValue<'static>>>(
self,
key: K,
value: V,
) -> Self
pub fn set<K: Borrow<str>, V: Into<ConfigValue<'static>>>( self, key: K, value: V, ) -> Self
Set config into configuration by programming, or from command line arguments.
Sourcepub fn set_cargo_env(self, cargo: Cargo) -> Self
pub fn set_cargo_env(self, cargo: Cargo) -> Self
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();
Sourcepub fn set_init<F: FnOnce(&Configuration) -> Result<(), ConfigError> + 'static>(
self,
f: F,
) -> Self
pub fn set_init<F: FnOnce(&Configuration) -> Result<(), ConfigError> + 'static>( self, f: F, ) -> Self
Set init func, which will be run after env source loaded.
Sourcepub fn init(self) -> Result<Configuration, ConfigError>
pub fn init(self) -> Result<Configuration, ConfigError>
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
rand
to enable random value source. - Feature
toml
to enable toml supports. - Feature
yaml
to enable yaml supports. - Feature
json
to enable json supports.
Always be enabled. ↩
See Supported File Formats for details. ↩
Auto Trait Implementations§
impl !Freeze for PredefinedConfigurationBuilder
impl !RefUnwindSafe for PredefinedConfigurationBuilder
impl !Send for PredefinedConfigurationBuilder
impl !Sync for PredefinedConfigurationBuilder
impl Unpin for PredefinedConfigurationBuilder
impl !UnwindSafe for PredefinedConfigurationBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more