Skip to main content

Crate dotenv

Crate dotenv 

Source
Expand description

Load and use environment variables from .env files.

§Overview

This crate parses .env files with variable substitution support: $VAR, ${VAR}, ${VAR:-default}. It provides both convenience functions (for typical usage) and a builder-style Dotenv type (for fine-grained control).

§Quick start

dotenv::load().ok();

for (key, value) in dotenv::vars() {
    println!("{key}={value}");
}

§Available entry points

TaskFunction / Type
Load .env automaticallyload(), var(), vars()
Load a specific filefrom_path(), from_filename()
Load from a custom sourcefrom_read()
Builder with control over behaviourDotenv

Structs§

Dotenv
Parsed dotenv content

Enums§

Error
Errors that can occur when working with dotenv files.

Functions§

from_filename
Create Dotenv from the specified file.
from_path
Create Dotenv from the specified path.
from_read
Create Dotenv from any Read implementor.
load
Load the .env file from the current directory or its parents.
var
Get the value for an environment variable.
vars
Return an iterator of (key, value) pairs for all environment variables of the current process.

Type Aliases§

Result