You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+20-7Lines changed: 20 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -304,11 +304,10 @@ You can use [std::env::var](https://doc.rust-lang.org/std/env/fn.var.html) to fe
304
304
key from the current process. It will report error if the environment variable is not present, and it also
305
305
includes other checks to avoid silent failures.
306
306
307
-
To set environment variables, you can use [std::env::set_var](https://doc.rust-lang.org/std/env/fn.set_var.html).
308
-
There are also other related APIs in the [std::env](https://doc.rust-lang.org/std/env/index.html) module.
307
+
To set environment variables in **single-threaded programs**, you can use [std::env::set_var] and
308
+
[std::env::remove_var]. While those functions **[must not be called]** if any other threads might be running, you can
309
+
always set environment variables for one command at a time, by putting the assignments before the command:
309
310
310
-
To set environment variables for the command only, you can put the assignments before the command.
311
-
Like this:
312
311
```rust
313
312
run_cmd!(FOO=100/tmp/test_run_cmd_lib.sh)?;
314
313
```
@@ -330,9 +329,23 @@ You can use the [glob](https://github.com/rust-lang-nursery/glob) package instea
330
329
331
330
#### Thread Safety
332
331
333
-
This library tries very hard to not set global states, so parallel `cargo test` can be executed just fine.
334
-
The only known APIs not supported in multi-thread environment are the
335
-
[`tls_init!`](https://docs.rs/cmd_lib/latest/cmd_lib/macro.tls_init.html)/[`tls_get!`](https://docs.rs/cmd_lib/latest/cmd_lib/macro.tls_get.html)/[`tls_set!`](https://docs.rs/cmd_lib/latest/cmd_lib/macro.tls_set.html) macros, and you should only use them for *thread local* variables.
332
+
This library tries very hard to not set global state, so parallel `cargo test` can be executed just fine.
333
+
That said, there are some limitations to be aware of:
334
+
335
+
-[std::env::set_var] and [std::env::remove_var]**[must not be called]** in a multi-threaded program
0 commit comments