Skip to content

get

Returns the value of key in dotenv content, or None when it is not assigned.

When a key is assigned more than once the last assignment wins, like a shell sourcing the file. See parse for the accepted syntax.

use helpers4::env::get;

Cargo feature env (enabled by default). To compile only this module:

cargo add helpers4 --no-default-features --features env

or in Cargo.toml:

[dependencies]
helpers4 = { version = "0.0.5", default-features = false, features = ["env"] }
pub fn get(content: &str, key: &str) -> Option<String>
ParameterTypeDescription
content&strThe dotenv text to read.
key&strThe variable name to look up.

Option<String>

use helpers4::env::get;

let content = "HOST=localhost\nPORT=80\nPORT=8080\n";
assert_eq!(get(content, "PORT").as_deref(), Some("8080"));
assert_eq!(get(content, "MISSING"), None);

src/env/get.rs