Skip to main content

EnvironmentProvider

Trait EnvironmentProvider 

Source
pub trait EnvironmentProvider: Send + Sync {
    // Required method
    fn get_var(&self, key: &str) -> Option<String>;

    // Provided method
    fn has_var(&self, key: &str) -> bool { ... }
}
Expand description

Environment variable provider trait.

This trait abstracts environment variable access, allowing for mock implementations to be injected during testing.

Required Methods§

Source

fn get_var(&self, key: &str) -> Option<String>

Get the value of the specified environment variable.

§Arguments
  • key - Environment variable name
§Returns

Returns Some(value) if the environment variable exists and is valid, otherwise returns None.

Provided Methods§

Source

fn has_var(&self, key: &str) -> bool

Check if an environment variable exists.

§Arguments
  • key - Environment variable name
§Returns

Returns true if the environment variable exists, otherwise false.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§