Struct cfg_rs::Configuration
source · [−]pub struct Configuration { /* private fields */ }Expand description
Configuration Instance, See Examples, How to Initialize Configuration for details.
Implementations
sourceimpl Configuration
impl Configuration
sourcepub fn new() -> Self
pub fn new() -> Self
Create an empty Configuration.
If you want to use predefined sources, please try Configuration::with_predefined or Configuration::with_predefined_builder.
sourcepub fn register_kv<N: Into<String>>(self, name: N) -> ManualSource
pub fn register_kv<N: Into<String>>(self, name: N) -> ManualSource
Register key value manually.
sourcepub fn register_prefix_env(self, prefix: &str) -> Result<Self, ConfigError>
pub fn register_prefix_env(self, prefix: &str) -> Result<Self, ConfigError>
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
sourcepub 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. ↩
sourcepub fn register_random(self) -> Result<Self, ConfigError>
Available on crate feature rand only.
pub fn register_random(self) -> Result<Self, ConfigError>
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
sourcepub 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.
sourcepub fn refresh_ref(&self) -> Result<bool, ConfigError>
pub fn refresh_ref(&self) -> Result<bool, ConfigError>
Refresh all RefValues without change Configuration itself.
sourcepub fn refresh(&mut self) -> Result<bool, ConfigError>
pub fn refresh(&mut self) -> Result<bool, ConfigError>
Refresh all RefValues and Configuration itself.
sourcepub fn get<T: FromConfig>(&self, key: &str) -> Result<T, ConfigError>
pub fn get<T: FromConfig>(&self, key: &str) -> Result<T, ConfigError>
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]
sourcepub fn get_or<T: FromConfig>(&self, key: &str, def: T) -> Result<T, ConfigError>
pub fn get_or<T: FromConfig>(&self, key: &str, def: T) -> Result<T, ConfigError>
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.
sourcepub fn get_predefined<T: FromConfigWithPrefix>(&self) -> Result<T, ConfigError>
pub fn get_predefined<T: FromConfigWithPrefix>(&self) -> Result<T, ConfigError>
Get config with predefined key, which is automatically derived by FromConfig.
sourcepub fn source_names(&self) -> Vec<&str>
pub fn source_names(&self) -> Vec<&str>
Get source names, just for test.
sourcepub fn with_predefined_builder() -> PredefinedConfigurationBuilder
pub fn with_predefined_builder() -> PredefinedConfigurationBuilder
Create predefined sources builder, see init for details.
sourcepub fn with_predefined() -> Result<Self, ConfigError>
pub fn with_predefined() -> Result<Self, ConfigError>
Create predefined configuration, see init for details.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Configuration
impl Send for Configuration
impl !Sync for Configuration
impl Unpin for Configuration
impl !UnwindSafe for Configuration
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more