1
Fork 0

"what would rustfmt do"

This commit is contained in:
Tshepang Mbambo 2023-09-04 17:46:26 +02:00 committed by GitHub
parent bf1e3f31f9
commit d8c1533252
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -12,9 +12,9 @@
//! use std::process::Command; //! use std::process::Command;
//! //!
//! let output = Command::new("echo") //! let output = Command::new("echo")
//! .arg("Hello world") //! .arg("Hello world")
//! .output() //! .output()
//! .expect("Failed to execute command"); //! .expect("Failed to execute command");
//! //!
//! assert_eq!(b"Hello world\n", output.stdout.as_slice()); //! assert_eq!(b"Hello world\n", output.stdout.as_slice());
//! ``` //! ```
@ -154,12 +154,11 @@ use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner};
/// use std::process::Command; /// use std::process::Command;
/// ///
/// let mut child = Command::new("/bin/cat") /// let mut child = Command::new("/bin/cat")
/// .arg("file.txt") /// .arg("file.txt")
/// .spawn() /// .spawn()
/// .expect("failed to execute child"); /// .expect("failed to execute child");
/// ///
/// let ecode = child.wait() /// let ecode = child.wait().expect("failed to wait on child");
/// .expect("failed to wait on child");
/// ///
/// assert!(ecode.success()); /// assert!(ecode.success());
/// ``` /// ```
@ -481,15 +480,15 @@ impl fmt::Debug for ChildStderr {
/// ///
/// let output = if cfg!(target_os = "windows") { /// let output = if cfg!(target_os = "windows") {
/// Command::new("cmd") /// Command::new("cmd")
/// .args(["/C", "echo hello"]) /// .args(["/C", "echo hello"])
/// .output() /// .output()
/// .expect("failed to execute process") /// .expect("failed to execute process")
/// } else { /// } else {
/// Command::new("sh") /// Command::new("sh")
/// .arg("-c") /// .arg("-c")
/// .arg("echo hello") /// .arg("echo hello")
/// .output() /// .output()
/// .expect("failed to execute process") /// .expect("failed to execute process")
/// }; /// };
/// ///
/// let hello = output.stdout; /// let hello = output.stdout;
@ -502,8 +501,7 @@ impl fmt::Debug for ChildStderr {
/// use std::process::Command; /// use std::process::Command;
/// ///
/// let mut echo_hello = Command::new("sh"); /// let mut echo_hello = Command::new("sh");
/// echo_hello.arg("-c") /// echo_hello.arg("-c").arg("echo hello");
/// .arg("echo hello");
/// let hello_1 = echo_hello.output().expect("failed to execute process"); /// let hello_1 = echo_hello.output().expect("failed to execute process");
/// let hello_2 = echo_hello.output().expect("failed to execute process"); /// let hello_2 = echo_hello.output().expect("failed to execute process");
/// ``` /// ```
@ -576,8 +574,8 @@ impl Command {
/// use std::process::Command; /// use std::process::Command;
/// ///
/// Command::new("sh") /// Command::new("sh")
/// .spawn() /// .spawn()
/// .expect("sh command failed to start"); /// .expect("sh command failed to start");
/// ``` /// ```
#[stable(feature = "process", since = "1.0.0")] #[stable(feature = "process", since = "1.0.0")]
pub fn new<S: AsRef<OsStr>>(program: S) -> Command { pub fn new<S: AsRef<OsStr>>(program: S) -> Command {
@ -620,10 +618,10 @@ impl Command {
/// use std::process::Command; /// use std::process::Command;
/// ///
/// Command::new("ls") /// Command::new("ls")
/// .arg("-l") /// .arg("-l")
/// .arg("-a") /// .arg("-a")
/// .spawn() /// .spawn()
/// .expect("ls command failed to start"); /// .expect("ls command failed to start");
/// ``` /// ```
#[stable(feature = "process", since = "1.0.0")] #[stable(feature = "process", since = "1.0.0")]
pub fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Command { pub fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Command {
@ -650,9 +648,9 @@ impl Command {
/// use std::process::Command; /// use std::process::Command;
/// ///
/// Command::new("ls") /// Command::new("ls")
/// .args(["-l", "-a"]) /// .args(["-l", "-a"])
/// .spawn() /// .spawn()
/// .expect("ls command failed to start"); /// .expect("ls command failed to start");
/// ``` /// ```
#[stable(feature = "process", since = "1.0.0")] #[stable(feature = "process", since = "1.0.0")]
pub fn args<I, S>(&mut self, args: I) -> &mut Command pub fn args<I, S>(&mut self, args: I) -> &mut Command
@ -688,9 +686,9 @@ impl Command {
/// use std::process::Command; /// use std::process::Command;
/// ///
/// Command::new("ls") /// Command::new("ls")
/// .env("PATH", "/bin") /// .env("PATH", "/bin")
/// .spawn() /// .spawn()
/// .expect("ls command failed to start"); /// .expect("ls command failed to start");
/// ``` /// ```
#[stable(feature = "process", since = "1.0.0")] #[stable(feature = "process", since = "1.0.0")]
pub fn env<K, V>(&mut self, key: K, val: V) -> &mut Command pub fn env<K, V>(&mut self, key: K, val: V) -> &mut Command
@ -731,12 +729,12 @@ impl Command {
/// ).collect(); /// ).collect();
/// ///
/// Command::new("printenv") /// Command::new("printenv")
/// .stdin(Stdio::null()) /// .stdin(Stdio::null())
/// .stdout(Stdio::inherit()) /// .stdout(Stdio::inherit())
/// .env_clear() /// .env_clear()
/// .envs(&filtered_env) /// .envs(&filtered_env)
/// .spawn() /// .spawn()
/// .expect("printenv failed to start"); /// .expect("printenv failed to start");
/// ``` /// ```
#[stable(feature = "command_envs", since = "1.19.0")] #[stable(feature = "command_envs", since = "1.19.0")]
pub fn envs<I, K, V>(&mut self, vars: I) -> &mut Command pub fn envs<I, K, V>(&mut self, vars: I) -> &mut Command
@ -772,9 +770,9 @@ impl Command {
/// use std::process::Command; /// use std::process::Command;
/// ///
/// Command::new("ls") /// Command::new("ls")
/// .env_remove("PATH") /// .env_remove("PATH")
/// .spawn() /// .spawn()
/// .expect("ls command failed to start"); /// .expect("ls command failed to start");
/// ``` /// ```
#[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 {
@ -802,9 +800,9 @@ impl Command {
/// use std::process::Command; /// use std::process::Command;
/// ///
/// Command::new("ls") /// Command::new("ls")
/// .env_clear() /// .env_clear()
/// .spawn() /// .spawn()
/// .expect("ls command failed to start"); /// .expect("ls command failed to start");
/// ``` /// ```
#[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 {
@ -830,9 +828,9 @@ impl Command {
/// use std::process::Command; /// use std::process::Command;
/// ///
/// Command::new("ls") /// Command::new("ls")
/// .current_dir("/bin") /// .current_dir("/bin")
/// .spawn() /// .spawn()
/// .expect("ls command failed to start"); /// .expect("ls command failed to start");
/// ``` /// ```
/// ///
/// [`canonicalize`]: crate::fs::canonicalize /// [`canonicalize`]: crate::fs::canonicalize
@ -861,9 +859,9 @@ impl Command {
/// use std::process::{Command, Stdio}; /// use std::process::{Command, Stdio};
/// ///
/// Command::new("ls") /// Command::new("ls")
/// .stdin(Stdio::null()) /// .stdin(Stdio::null())
/// .spawn() /// .spawn()
/// .expect("ls command failed to start"); /// .expect("ls command failed to start");
/// ``` /// ```
#[stable(feature = "process", since = "1.0.0")] #[stable(feature = "process", since = "1.0.0")]
pub fn stdin<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Command { pub fn stdin<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Command {
@ -890,9 +888,9 @@ impl Command {
/// use std::process::{Command, Stdio}; /// use std::process::{Command, Stdio};
/// ///
/// Command::new("ls") /// Command::new("ls")
/// .stdout(Stdio::null()) /// .stdout(Stdio::null())
/// .spawn() /// .spawn()
/// .expect("ls command failed to start"); /// .expect("ls command failed to start");
/// ``` /// ```
#[stable(feature = "process", since = "1.0.0")] #[stable(feature = "process", since = "1.0.0")]
pub fn stdout<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Command { pub fn stdout<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Command {
@ -919,9 +917,9 @@ impl Command {
/// use std::process::{Command, Stdio}; /// use std::process::{Command, Stdio};
/// ///
/// Command::new("ls") /// Command::new("ls")
/// .stderr(Stdio::null()) /// .stderr(Stdio::null())
/// .spawn() /// .spawn()
/// .expect("ls command failed to start"); /// .expect("ls command failed to start");
/// ``` /// ```
#[stable(feature = "process", since = "1.0.0")] #[stable(feature = "process", since = "1.0.0")]
pub fn stderr<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Command { pub fn stderr<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Command {
@ -941,8 +939,8 @@ impl Command {
/// use std::process::Command; /// use std::process::Command;
/// ///
/// Command::new("ls") /// Command::new("ls")
/// .spawn() /// .spawn()
/// .expect("ls command failed to start"); /// .expect("ls command failed to start");
/// ``` /// ```
#[stable(feature = "process", since = "1.0.0")] #[stable(feature = "process", since = "1.0.0")]
pub fn spawn(&mut self) -> io::Result<Child> { pub fn spawn(&mut self) -> io::Result<Child> {
@ -963,9 +961,9 @@ impl Command {
/// use std::process::Command; /// use std::process::Command;
/// use std::io::{self, Write}; /// use std::io::{self, Write};
/// let output = Command::new("/bin/cat") /// let output = Command::new("/bin/cat")
/// .arg("file.txt") /// .arg("file.txt")
/// .output() /// .output()
/// .expect("failed to execute process"); /// .expect("failed to execute process");
/// ///
/// println!("status: {}", output.status); /// println!("status: {}", output.status);
/// io::stdout().write_all(&output.stdout).unwrap(); /// io::stdout().write_all(&output.stdout).unwrap();
@ -990,9 +988,9 @@ impl Command {
/// use std::process::Command; /// use std::process::Command;
/// ///
/// let status = Command::new("/bin/cat") /// let status = Command::new("/bin/cat")
/// .arg("file.txt") /// .arg("file.txt")
/// .status() /// .status()
/// .expect("failed to execute process"); /// .expect("failed to execute process");
/// ///
/// println!("process finished with: {status}"); /// println!("process finished with: {status}");
/// ///
@ -1558,9 +1556,9 @@ impl ExitStatus {
/// use std::process::Command; /// use std::process::Command;
/// ///
/// let status = Command::new("ls") /// let status = Command::new("ls")
/// .arg("/dev/nonexistent") /// .arg("/dev/nonexistent")
/// .status() /// .status()
/// .expect("ls could not be executed"); /// .expect("ls could not be executed");
/// ///
/// println!("ls: {status}"); /// println!("ls: {status}");
/// status.exit_ok().expect_err("/dev/nonexistent could be listed!"); /// status.exit_ok().expect_err("/dev/nonexistent could be listed!");
@ -1580,9 +1578,9 @@ impl ExitStatus {
/// use std::process::Command; /// use std::process::Command;
/// ///
/// let status = Command::new("mkdir") /// let status = Command::new("mkdir")
/// .arg("projects") /// .arg("projects")
/// .status() /// .status()
/// .expect("failed to execute mkdir"); /// .expect("failed to execute mkdir");
/// ///
/// if status.success() { /// if status.success() {
/// println!("'projects/' directory created"); /// println!("'projects/' directory created");
@ -1613,13 +1611,13 @@ impl ExitStatus {
/// use std::process::Command; /// use std::process::Command;
/// ///
/// let status = Command::new("mkdir") /// let status = Command::new("mkdir")
/// .arg("projects") /// .arg("projects")
/// .status() /// .status()
/// .expect("failed to execute mkdir"); /// .expect("failed to execute mkdir");
/// ///
/// match status.code() { /// match status.code() {
/// Some(code) => println!("Exited with status code: {code}"), /// Some(code) => println!("Exited with status code: {code}"),
/// None => println!("Process terminated by signal") /// None => println!("Process terminated by signal")
/// } /// }
/// ``` /// ```
#[must_use] #[must_use]