| Crates.io | ephemeral-env |
| lib.rs | ephemeral-env |
| version | 1.0.0 |
| created_at | 2025-11-26 11:47:38.297555+00 |
| updated_at | 2025-12-16 23:18:26.591225+00 |
| description | A utility for creating ephemeral environments which are reverted on Drop |
| homepage | |
| repository | https://gitlab.com/gmb/ephemeral-env-rs |
| max_upload_size | |
| id | 1951308 |
| size | 22,810 |
If your code is driven by environment variables you'll often find yourself writing tests like this:
#[test]
fn test_something_works() {
unsafe {
std::env::set_var("THATS_NOT_MY_COW", "It goes baa");
}
do_the_thing();
unsafe {
std::env::remove_var("THATS_NOT_MY_COW");
}
}
The trouble with this is twofold:
ephemeral-env solves this by:
unsafe {...}.Rewriting the example above with ephemeral-env would give you:
#[test]
fn test_something_works() {
let test_env = ephemeral_env::EphemeralEnv::from_env_sync().unwrap();
test_env::set_var("THATS_NOT_MY_COW", "It goes baa");
do_the_thing();
}