Skip to main content

load

Function load 

Source
pub fn load() -> Result<(), Error>
Expand description

Loads the .env file from the current working directory.

Each key-value pair found in the file is set as an environment variable for the current process, subject to these rules:

  1. A variable already present in the environment is not overwritten.
  2. When the same key appears multiple times in .env, the first declaration takes effect.

§Errors

Returns Error if the file cannot be read (missing, permissions, etc.) or if the .env file is malformed.

§Example

fn main() {
    if let Err(e) = dotenv::load() {
        eprintln!("Failed to load .env: {e}");
    }
}