1
Fork 0

More compelling env_clear() examples

This commit is contained in:
Kornel 2025-01-06 23:39:53 +00:00
parent 243d2ca4db
commit 85a71ea0c7
No known key found for this signature in database

View file

@ -868,13 +868,17 @@ impl Command {
/// ///
/// # Examples /// # 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 /// ```no_run
/// use std::process::Command; /// use std::process::Command;
/// ///
/// Command::new("ls") /// Command::new("git")
/// .env_remove("PATH") /// .arg("commit")
/// .spawn() /// .env_remove("GIT_DIR")
/// .expect("ls command failed to start"); /// .spawn()?;
/// # std::io::Result::Ok(())
/// ``` /// ```
#[stable(feature = "process", since = "1.0.0")] #[stable(feature = "process", since = "1.0.0")]
pub fn env_remove<K: AsRef<OsStr>>(&mut self, key: K) -> &mut Command { pub fn env_remove<K: AsRef<OsStr>>(&mut self, key: K) -> &mut Command {
@ -896,13 +900,17 @@ impl Command {
/// ///
/// # Examples /// # 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 /// ```no_run
/// use std::process::Command; /// use std::process::Command;
/// ///
/// Command::new("ls") /// Command::new("sort")
/// .arg("file.txt")
/// .env_clear() /// .env_clear()
/// .spawn() /// .spawn()?;
/// .expect("ls command failed to start"); /// # std::io::Result::Ok(())
/// ``` /// ```
#[stable(feature = "process", since = "1.0.0")] #[stable(feature = "process", since = "1.0.0")]
pub fn env_clear(&mut self) -> &mut Command { pub fn env_clear(&mut self) -> &mut Command {