MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / set

Method set

crates/openshell-cli/tests/helpers/mod.rs:38–51  ·  view source on GitHub ↗

Acquire the global env-var lock and atomically set one or more environment variables. All variables are restored to their prior state (or removed) when the guard is dropped.

(pairs: &[(&'static str, &str)])

Source from the content-addressed store, hash-verified

36 /// environment variables. All variables are restored to their prior
37 /// state (or removed) when the guard is dropped.
38 pub fn set(pairs: &[(&'static str, &str)]) -> Self {
39 let lock = ENV_LOCK
40 .lock()
41 .unwrap_or_else(std::sync::PoisonError::into_inner);
42 let mut vars = Vec::with_capacity(pairs.len());
43 for &(key, value) in pairs {
44 let original = std::env::var(key).ok();
45 unsafe {
46 std::env::set_var(key, value);
47 }
48 vars.push(SavedVar { key, original });
49 }
50 Self { vars, _lock: lock }
51 }
52}
53
54#[allow(unsafe_code)]

Callers

nothing calls this directly

Calls 2

lenMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected