Struct smart_config::fallback::Env
source · pub struct Env(pub &'static str);
Expand description
Gets a string value from the specified env variable.
§Examples
use smart_config::{fallback, testing, DescribeConfig, DeserializeConfig};
#[derive(DescribeConfig, DeserializeConfig)]
struct TestConfig {
/// Log directives. Always read from `RUST_LOG` env var in addition to
/// the conventional sources.
#[config(default_t = "info".into(), fallback = &fallback::Env("RUST_LOG"))]
log_directives: String,
}
let mut tester = testing::Tester::default();
let config: TestConfig = tester.test(smart_config::config!())?;
// Without env var set or other sources, the param will assume the default value.
assert_eq!(config.log_directives, "info");
tester.set_env("RUST_LOG", "warn");
let config: TestConfig = tester.test(smart_config::config!())?;
assert_eq!(config.log_directives, "warn");
// Mock env vars are still set here, but fallbacks have lower priority
// than other sources.
let input = smart_config::config!("log_directives": "info,my_crate=debug");
let config = tester.test(input)?;
assert_eq!(config.log_directives, "info,my_crate=debug");
Tuple Fields§
§0: &'static str
Implementations§
Trait Implementations§
source§impl FallbackSource for Env
impl FallbackSource for Env
source§fn provide_value(&self) -> Option<WithOrigin>
fn provide_value(&self) -> Option<WithOrigin>
Potentially provides a value for the param. Read more
impl Copy for Env
Auto Trait Implementations§
impl Freeze for Env
impl RefUnwindSafe for Env
impl Send for Env
impl Sync for Env
impl Unpin for Env
impl UnwindSafe for Env
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)