1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
pub use crateDotenv;
pub use crateError;
pub type Result<T> = Result;
use env;
use ffi;
use fs;
use io;
use Read;
use Path;
use PathBuf;
use Once;
static LOAD: Once = new;
/// Get the value for an environment variable.
///
/// Automatically loads `.env` on first call (if present and not yet loaded).
/// Values are read from the **current process environment**, not directly from
/// the `.env` file — so any value set by a previous caller or the shell is visible.
///
/// # Errors
///
/// Returns [`Error::Env`] if the variable contains non-unicode data.
///
/// # Examples
///
/// ```no_run
/// let value = dotenv::var("HOME").unwrap();
/// println!("{}", value);
/// ```
/// Return an iterator of `(key, value)` pairs for all environment variables
/// of the current process.
///
/// Automatically loads `.env` on first call. The returned iterator is a
/// snapshot of the process environment at the time of invocation —
/// subsequent modifications are not reflected.
///
/// # Examples
///
/// ```no_run
/// use std::io;
///
/// for (key, value) in dotenv::vars() {
/// println!("{key}={value}");
/// }
/// ```
/// Load the `.env` file from the current directory or its parents.
///
/// Searches upward from the current working directory until `.env` is found.
/// The first call loads variables; subsequent calls are no-ops through
/// [`Dotenv::load`] (existing variables are preserved).
///
/// # Errors
///
/// Returns [`Error::Io`] if no `.env` file is found or it cannot be read.
///
/// # Examples
///
/// ```no_run
/// dotenv::load().ok();
/// ```
/// Create [`Dotenv`] from the specified file.
///
/// Searches upward from the current working directory for the given filename.
///
/// # Errors
///
/// Returns [`Error::Io`] if the file is not found or cannot be read.
/// Create [`Dotenv`] from the specified path.
///
/// # Errors
///
/// Returns [`Error::Io`] if the file cannot be read.
/// Create [`Dotenv`] from any [`Read`] implementor.
///
/// This is useful for loading environment variables from in-memory buffers,
/// IPC streams, or network connections.
///
/// # Errors
///
/// Returns [`Error::Io`] if reading from the source fails.
///
/// # Examples
///
/// ```
/// use std::io::Cursor;
///
/// let input = Cursor::new(b"FOO=bar\nBAZ=qux\n");
/// let dotenv = dotenv::from_read(input).unwrap();
/// for (key, value) in dotenv.iter() {
/// println!("{key}={value}");
/// }
/// ```