Skip to main content

OrEnvExt

Trait OrEnvExt 

Source
pub trait OrEnvExt: Sized {
    // Required method
    fn or_env_mut(&mut self, env_var: &'static str) -> Result<&mut Self>;

    // Provided method
    fn or_env(self, env_var: &'static str) -> Result<Self> { ... }
}

Required Methods§

Source

fn or_env_mut(&mut self, env_var: &'static str) -> Result<&mut Self>

If the arg is not set, initialize the arg from env by mutating the arg in place. Used to proactively initialize and validate args.

Provided Methods§

Source

fn or_env(self, env_var: &'static str) -> Result<Self>

Analogous to Option::or_else. Takes ownership of the arg if set, otherwise initializes the arg from env. Used to initialize args lazily. Also has good ergonomics with Result / Option chains.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl OrEnvExt for bool

Source§

fn or_env_mut(&mut self, env_var: &'static str) -> Result<&mut bool>

Source§

impl<T> OrEnvExt for Option<T>
where T: FromStr, T::Err: Into<Error>,

Source§

fn or_env_mut(&mut self, env_var: &'static str) -> Result<&mut Option<T>>

Implementors§