Skip to content

env

Dotenv (.env) helpers working on plain text: no file or process-environment access, so they are deterministic and easy to test. Read the file yourself, edit the content here, and write it back.

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.7", default-features = false, features = ["env"] }

Import path: helpers4::env.

ItemWhat it does
getReturns the value of key in dotenv content, or None when it is not assigned.
get_boolReturns key in dotenv content parsed as a boolean, or default when it is absent or not recognized.
get_durationReturns key in dotenv content parsed as a human-written duration ("1h30m", "2d", "500ms"), or default when it is absent or does not parse.
get_intReturns key in dotenv content parsed as an integer, or default when it is absent or not a valid i64 (a decimal integer, optionally signed; no underscores, no 0x/0b prefixes).
get_listReturns key in dotenv content split on separator into a list, or default when it is absent.
parseParses dotenv content into (key, value) pairs, in file order.
removeRemoves every assignment of key from dotenv content and returns the new content.
setSets key to value in dotenv content and returns the new content.

Documented on the page of the helper that returns them.

TypeReturned by
InvalidKeyErrorset