Skip to main content

present

Function present 

Source
pub fn present(raw: Option<&str>) -> Option<&str>
Expand description

A value if it is present, None if it is absent or blank.

Blank is absent, and every other reader in this crate goes through this function. Leading and trailing whitespace is stripped; what is left, if anything, is the value.

A templated deployment whose source was empty produces PORT= routinely — an .env line with nothing after the =, a substituted variable that resolved to nothing — and treating that as “configured, to the empty string” produces failures a long way from their cause.

§Examples

use env_reader::present;

assert_eq!(present(Some("orders")), Some("orders"));
assert_eq!(present(Some("  8080  ")), Some("8080"));
assert_eq!(present(Some("   ")), None);
assert_eq!(present(Some("")), None);
assert_eq!(present(None), None);