Skip to content

Commit

Permalink
Unrolled build for rust-lang#135176
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#135176 - kornelski:env-example, r=cuviper

More compelling env_clear() examples

`ls` isn't a command that people usually set env vars for, and `PATH` in particular isn't even used by `ls`.
  • Loading branch information
rust-timer authored Jan 8, 2025
2 parents 1f81f90 + 85a71ea commit 92533f5
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions library/std/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -868,13 +868,17 @@ impl Command {
///
/// # Examples
///
/// Prevent any inherited `GIT_DIR` variable from changing the target of the `git` command,
/// while allowing all other variables, like `GIT_AUTHOR_NAME`.
///
/// ```no_run
/// use std::process::Command;
///
/// Command::new("ls")
/// .env_remove("PATH")
/// .spawn()
/// .expect("ls command failed to start");
/// Command::new("git")
/// .arg("commit")
/// .env_remove("GIT_DIR")
/// .spawn()?;
/// # std::io::Result::Ok(())
/// ```
#[stable(feature = "process", since = "1.0.0")]
pub fn env_remove<K: AsRef<OsStr>>(&mut self, key: K) -> &mut Command {
Expand All @@ -896,13 +900,17 @@ impl Command {
///
/// # Examples
///
/// The behavior of `sort` is affected by `LANG` and `LC_*` environment variables.
/// Clearing the environment makes `sort`'s behavior independent of the parent processes' language.
///
/// ```no_run
/// use std::process::Command;
///
/// Command::new("ls")
/// Command::new("sort")
/// .arg("file.txt")
/// .env_clear()
/// .spawn()
/// .expect("ls command failed to start");
/// .spawn()?;
/// # std::io::Result::Ok(())
/// ```
#[stable(feature = "process", since = "1.0.0")]
pub fn env_clear(&mut self) -> &mut Command {
Expand Down

0 comments on commit 92533f5

Please sign in to comment.