usestd::ffi::OsString;/// RAII guard that sets an env var and restores the old value on drop.
/// Tests using this guard MUST be annotated with `#[serial_test::serial]`
/// (or `#[serial_test::serial(env)]`) to prevent concurrent env mutation.
pubstructEnvGuard{key:&'staticstr,
old:Option<OsString>,
}implEnvGuard{pubfnset(key:&'staticstr, value:&str)->Self{let old =std::env::var_os(key);// SAFETY: callers must use #[serial_test::serial] to prevent races.
unsafe{std::env::set_var(key, value)};Self{ key, old }}}implDrop forEnvGuard{fndrop(&mutself){ifletSome(v)=&self.old {unsafe{std::env::set_var(self.key, v)};}else{unsafe{std::env::remove_var(self.key)};}}}