Skip to content

remove

Removes every assignment of key from dotenv content and returns the new content.

Comments, blank lines and other variables are left untouched. Removing a key that is not assigned returns the content unchanged.

use helpers4::env::remove;

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 remove(content: &str, key: &str) -> String
ParameterTypeDescription
content&strThe dotenv text to edit.
key&strThe variable name to remove every assignment of.

String

use helpers4::env::remove;

assert_eq!(remove("A=1\nB=2\nA=3\n", "A"), "B=2\n");

src/env/remove.rs