pub fn validate(environment: &LoadedEnvironment) -> Result<(), ApplyError>Expand description
Checks that the process environment can hold every loaded key and value.
Runs the checks of apply without changing anything, so it is safe to
call from any thread, for example to report a bad .env file early. A key
must not be empty and must not contain NUL or =. A value must not contain
NUL. Keys are checked in sorted order.
§Errors
Returns the first problem found:
ApplyError::EmptyKeyif a key is empty.ApplyError::InvalidKeyif a key contains NUL or=.ApplyError::InvalidValueif a value contains NUL.
§Examples
With PORT=8080 and a TOKEN value that contains a NUL byte in .env:
use adotenv::load::load_cascade;
use adotenv_process::{validate, ApplyError};
let loaded = load_cascade(&dir, "")?;
let error = validate(&loaded).unwrap_err();
assert_eq!(error, ApplyError::InvalidValue { key: "TOKEN".to_string() });
assert_eq!(error.to_string(), r#"environment value for "TOKEN" contains NUL"#);