Crates.io | dotenvs |
lib.rs | dotenvs |
version | 0.1.0 |
source | src |
created_at | 2022-04-28 09:50:49.550723 |
updated_at | 2022-11-24 15:19:25.479847 |
description | A correct dotenv library |
homepage | https://github.com/arniu/dotenvs-rs |
repository | https://github.com/arniu/dotenvs-rs |
max_upload_size | |
id | 576713 |
size | 25,734 |
A correct dotenv library, which supports:
BASIC=basic
#
are treated as comments#
marks the beginning of a comment (unless when the value is wrapped in quotes)MULTILINE="new\nline"
becomes
MULTILINE: "new
line"
$KEY
will expand any env with the name KEY
${KEY}
will expand any env with the name KEY
\$KEY
will escape the $KEY
rather than expand${KEY:-default}
will first attempt to expand any env with the name KEY
. If not one, then it will return default
The easiest and most common usage consists on calling load
when the
application starts, which will load environment variables from a file named
.env
in the current directory or any of its parents.
If you need more control about the file name or its location, you can
use the from_filename
, from_path
or from_read
.
A .env
file looks like this:
# a comment, will be ignored
REDIS_ADDRESS=localhost:6379
MEANING_OF_LIFE=42
You can optionally prefix each line with the word export
, which will
conveniently allow you to source the whole file on your shell.
A sample project using dotenv would look like this:
fn main() {
for (key, value) in dotenv::vars() {
println!("{}: {}", key, value);
}
}