Skip to main content

FromEnv

Trait FromEnv 

Source
pub trait FromEnv: Sized {
    // Required method
    fn from_env_with_prefix(prefix: &str) -> Result<Self, FromEnvError>;

    // Provided method
    fn from_env() -> Result<Self, FromEnvError> { ... }
}
Expand description

Trait for types that can be constructed from environment variables.

Usually derived with #[derive(FromEnv)].

Required Methods§

Source

fn from_env_with_prefix(prefix: &str) -> Result<Self, FromEnvError>

Load Self from environment variables, prepending prefix to each env-var name derived from field names.

This is used internally to support nested structs. Each parent field passes its own SCREAMING_SNAKE name plus _ as the child’s prefix.

Provided Methods§

Source

fn from_env() -> Result<Self, FromEnvError>

Load Self from environment variables using an empty prefix.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§