}
impl AsInner<imp::Process> for Child {
- fn as_inner(&self) -> &imp::Process { &self.handle }
+ fn as_inner(&self) -> &imp::Process {
+ &self.handle
+ }
}
impl FromInner<(imp::Process, imp::StdioPipes)> for Child {
}
impl IntoInner<imp::Process> for Child {
- fn into_inner(self) -> imp::Process { self.handle }
+ fn into_inner(self) -> imp::Process {
+ self.handle
+ }
}
#[stable(feature = "std_debug", since = "1.16.0")]
/// [dropped]: ../ops/trait.Drop.html
#[stable(feature = "process", since = "1.0.0")]
pub struct ChildStdin {
- inner: AnonPipe
+ inner: AnonPipe,
}
#[stable(feature = "process", since = "1.0.0")]
}
impl AsInner<AnonPipe> for ChildStdin {
- fn as_inner(&self) -> &AnonPipe { &self.inner }
+ fn as_inner(&self) -> &AnonPipe {
+ &self.inner
+ }
}
impl IntoInner<AnonPipe> for ChildStdin {
- fn into_inner(self) -> AnonPipe { self.inner }
+ fn into_inner(self) -> AnonPipe {
+ self.inner
+ }
}
impl FromInner<AnonPipe> for ChildStdin {
/// [dropped]: ../ops/trait.Drop.html
#[stable(feature = "process", since = "1.0.0")]
pub struct ChildStdout {
- inner: AnonPipe
+ inner: AnonPipe,
}
#[stable(feature = "process", since = "1.0.0")]
}
impl AsInner<AnonPipe> for ChildStdout {
- fn as_inner(&self) -> &AnonPipe { &self.inner }
+ fn as_inner(&self) -> &AnonPipe {
+ &self.inner
+ }
}
impl IntoInner<AnonPipe> for ChildStdout {
- fn into_inner(self) -> AnonPipe { self.inner }
+ fn into_inner(self) -> AnonPipe {
+ self.inner
+ }
}
impl FromInner<AnonPipe> for ChildStdout {
/// [dropped]: ../ops/trait.Drop.html
#[stable(feature = "process", since = "1.0.0")]
pub struct ChildStderr {
- inner: AnonPipe
+ inner: AnonPipe,
}
#[stable(feature = "process", since = "1.0.0")]
}
impl AsInner<AnonPipe> for ChildStderr {
- fn as_inner(&self) -> &AnonPipe { &self.inner }
+ fn as_inner(&self) -> &AnonPipe {
+ &self.inner
+ }
}
impl IntoInner<AnonPipe> for ChildStderr {
- fn into_inner(self) -> AnonPipe { self.inner }
+ fn into_inner(self) -> AnonPipe {
+ self.inner
+ }
}
impl FromInner<AnonPipe> for ChildStderr {
/// ```
#[stable(feature = "process", since = "1.0.0")]
pub fn args<I, S>(&mut self, args: I) -> &mut Command
- where I: IntoIterator<Item=S>, S: AsRef<OsStr>
+ where
+ I: IntoIterator<Item = S>,
+ S: AsRef<OsStr>,
{
for arg in args {
self.arg(arg.as_ref());
/// ```
#[stable(feature = "process", since = "1.0.0")]
pub fn env<K, V>(&mut self, key: K, val: V) -> &mut Command
- where K: AsRef<OsStr>, V: AsRef<OsStr>
+ where
+ K: AsRef<OsStr>,
+ V: AsRef<OsStr>,
{
self.inner.env_mut().set(key.as_ref(), val.as_ref());
self
/// ```
#[stable(feature = "command_envs", since = "1.19.0")]
pub fn envs<I, K, V>(&mut self, vars: I) -> &mut Command
- where I: IntoIterator<Item=(K, V)>, K: AsRef<OsStr>, V: AsRef<OsStr>
+ where
+ I: IntoIterator<Item = (K, V)>,
+ K: AsRef<OsStr>,
+ V: AsRef<OsStr>,
{
for (ref key, ref val) in vars {
self.inner.env_mut().set(key.as_ref(), val.as_ref());
/// ```
#[stable(feature = "process", since = "1.0.0")]
pub fn output(&mut self) -> io::Result<Output> {
- self.inner.spawn(imp::Stdio::MakePipe, false).map(Child::from_inner)
+ self.inner
+ .spawn(imp::Stdio::MakePipe, false)
+ .map(Child::from_inner)
.and_then(|p| p.wait_with_output())
}
/// ```
#[stable(feature = "process", since = "1.0.0")]
pub fn status(&mut self) -> io::Result<ExitStatus> {
- self.inner.spawn(imp::Stdio::Inherit, true).map(Child::from_inner)
- .and_then(|mut p| p.wait())
+ self.inner
+ .spawn(imp::Stdio::Inherit, true)
+ .map(Child::from_inner)
+ .and_then(|mut p| p.wait())
}
}
}
impl AsInner<imp::Command> for Command {
- fn as_inner(&self) -> &imp::Command { &self.inner }
+ fn as_inner(&self) -> &imp::Command {
+ &self.inner
+ }
}
impl AsInnerMut<imp::Command> for Command {
- fn as_inner_mut(&mut self) -> &mut imp::Command { &mut self.inner }
+ fn as_inner_mut(&mut self) -> &mut imp::Command {
+ &mut self.inner
+ }
}
/// The output of a finished process.
#[stable(feature = "process_output_debug", since = "1.7.0")]
impl fmt::Debug for Output {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
-
let stdout_utf8 = str::from_utf8(&self.stdout);
let stdout_debug: &dyn fmt::Debug = match stdout_utf8 {
Ok(ref str) => str,
- Err(_) => &self.stdout
+ Err(_) => &self.stdout,
};
let stderr_utf8 = str::from_utf8(&self.stderr);
let stderr_debug: &dyn fmt::Debug = match stderr_utf8 {
Ok(ref str) => str,
- Err(_) => &self.stderr
+ Err(_) => &self.stderr,
};
fmt.debug_struct("Output")
/// assert_eq!(String::from_utf8_lossy(&output.stdout), "!dlrow ,olleH");
/// ```
#[stable(feature = "process", since = "1.0.0")]
- pub fn piped() -> Stdio { Stdio(imp::Stdio::MakePipe) }
+ pub fn piped() -> Stdio {
+ Stdio(imp::Stdio::MakePipe)
+ }
/// The child inherits from the corresponding parent descriptor.
///
/// io::stdout().write_all(&output.stdout).unwrap();
/// ```
#[stable(feature = "process", since = "1.0.0")]
- pub fn inherit() -> Stdio { Stdio(imp::Stdio::Inherit) }
+ pub fn inherit() -> Stdio {
+ Stdio(imp::Stdio::Inherit)
+ }
/// This stream will be ignored. This is the equivalent of attaching the
/// stream to `/dev/null`
/// // Ignores any piped-in input
/// ```
#[stable(feature = "process", since = "1.0.0")]
- pub fn null() -> Stdio { Stdio(imp::Stdio::Null) }
+ pub fn null() -> Stdio {
+ Stdio(imp::Stdio::Null)
+ }
}
impl FromInner<imp::Stdio> for Stdio {
}
impl AsInner<imp::ExitStatus> for ExitStatus {
- fn as_inner(&self) -> &imp::ExitStatus { &self.0 }
+ fn as_inner(&self) -> &imp::ExitStatus {
+ &self.0
+ }
}
impl FromInner<imp::ExitStatus> for ExitStatus {
}
let status = self.wait()?;
- Ok(Output {
- status,
- stdout,
- stderr,
- })
+ Ok(Output { status, stdout, stderr })
}
}
#[cfg_attr(not(test), lang = "termination")]
#[unstable(feature = "termination_trait_lib", issue = "43301")]
#[rustc_on_unimplemented(
- message="`main` has invalid return type `{Self}`",
- label="`main` can only return types that implement `{Termination}`")]
+ message = "`main` has invalid return type `{Self}`",
+ label = "`main` can only return types that implement `{Termination}`"
+)]
pub trait Termination {
/// Is called to get the representation of the value as status code.
/// This status code is returned to the operating system.
#[unstable(feature = "termination_trait_lib", issue = "43301")]
impl Termination for () {
#[inline]
- fn report(self) -> i32 { ExitCode::SUCCESS.report() }
+ fn report(self) -> i32 {
+ ExitCode::SUCCESS.report()
+ }
}
#[unstable(feature = "termination_trait_lib", issue = "43301")]
#[unstable(feature = "termination_trait_lib", issue = "43301")]
impl Termination for ! {
- fn report(self) -> i32 { self }
+ fn report(self) -> i32 {
+ self
+ }
}
#[unstable(feature = "termination_trait_lib", issue = "43301")]
mod tests {
use crate::io::prelude::*;
+ use super::{Command, Output, Stdio};
use crate::io::ErrorKind;
use crate::str;
- use super::{Command, Output, Stdio};
// FIXME(#10380) these tests should not all be ignored on android.
fn signal_reported_right() {
use crate::os::unix::process::ExitStatusExt;
- let mut p = Command::new("/bin/sh")
- .arg("-c").arg("read a")
- .stdin(Stdio::piped())
- .spawn().unwrap();
+ let mut p =
+ Command::new("/bin/sh").arg("-c").arg("read a").stdin(Stdio::piped()).spawn().unwrap();
p.kill().unwrap();
match p.wait().unwrap().signal() {
- Some(9) => {},
- result => panic!("not terminated by signal 9 (instead, {:?})",
- result),
+ Some(9) => {}
+ result => panic!("not terminated by signal 9 (instead, {:?})", result),
}
}
#[cfg_attr(any(windows, target_os = "android", target_os = "vxworks"), ignore)]
fn set_current_dir_works() {
let mut cmd = Command::new("/bin/sh");
- cmd.arg("-c").arg("pwd")
- .current_dir("/")
- .stdout(Stdio::piped());
+ cmd.arg("-c").arg("pwd").current_dir("/").stdout(Stdio::piped());
assert_eq!(run_output(cmd), "/\n");
}
#[cfg_attr(any(windows, target_os = "android", target_os = "vxworks"), ignore)]
fn stdin_works() {
let mut p = Command::new("/bin/sh")
- .arg("-c").arg("read line; echo $line")
- .stdin(Stdio::piped())
- .stdout(Stdio::piped())
- .spawn().unwrap();
+ .arg("-c")
+ .arg("read line; echo $line")
+ .stdin(Stdio::piped())
+ .stdout(Stdio::piped())
+ .spawn()
+ .unwrap();
p.stdin.as_mut().unwrap().write("foobar".as_bytes()).unwrap();
drop(p.stdin.take());
let mut out = String::new();
fn test_process_output_fail_to_start() {
match Command::new("/no-binary-by-this-name-should-exist").output() {
Err(e) => assert_eq!(e.kind(), ErrorKind::NotFound),
- Ok(..) => panic!()
+ Ok(..) => panic!(),
}
}
#[test]
#[cfg_attr(any(target_os = "vxworks", target_os = "android"), ignore)]
fn test_process_output_output() {
- let Output {status, stdout, stderr}
- = if cfg!(target_os = "windows") {
- Command::new("cmd").args(&["/C", "echo hello"]).output().unwrap()
- } else {
- Command::new("echo").arg("hello").output().unwrap()
- };
+ let Output { status, stdout, stderr } = if cfg!(target_os = "windows") {
+ Command::new("cmd").args(&["/C", "echo hello"]).output().unwrap()
+ } else {
+ Command::new("echo").arg("hello").output().unwrap()
+ };
let output_str = str::from_utf8(&stdout).unwrap();
assert!(status.success());
#[test]
#[cfg_attr(any(target_os = "vxworks", target_os = "android"), ignore)]
fn test_process_output_error() {
- let Output {status, stdout, stderr}
- = if cfg!(target_os = "windows") {
- Command::new("cmd").args(&["/C", "mkdir ."]).output().unwrap()
- } else {
- Command::new("mkdir").arg("./").output().unwrap()
- };
+ let Output { status, stdout, stderr } = if cfg!(target_os = "windows") {
+ Command::new("cmd").args(&["/C", "mkdir ."]).output().unwrap()
+ } else {
+ Command::new("mkdir").arg("./").output().unwrap()
+ };
assert!(status.code() == Some(1));
assert_eq!(stdout, Vec::new());
Command::new("echo").arg("hello").stdout(Stdio::piped()).spawn().unwrap()
};
- let Output {status, stdout, stderr} = prog.wait_with_output().unwrap();
+ let Output { status, stdout, stderr } = prog.wait_with_output().unwrap();
let output_str = str::from_utf8(&stdout).unwrap();
assert!(status.success());
assert_eq!(stderr, Vec::new());
}
- #[cfg(all(unix, not(target_os="android")))]
+ #[cfg(all(unix, not(target_os = "android")))]
pub fn env_cmd() -> Command {
Command::new("env")
}
- #[cfg(target_os="android")]
+ #[cfg(target_os = "android")]
pub fn env_cmd() -> Command {
let mut cmd = Command::new("/system/bin/sh");
cmd.arg("-c").arg("set");
let result = cmd.output().unwrap();
let output = String::from_utf8_lossy(&result.stdout).to_string();
- assert!(output.contains("RUN_TEST_NEW_ENV=123"),
- "didn't find RUN_TEST_NEW_ENV inside of:\n\n{}", output);
+ assert!(
+ output.contains("RUN_TEST_NEW_ENV=123"),
+ "didn't find RUN_TEST_NEW_ENV inside of:\n\n{}",
+ output
+ );
}
#[test]
let result = env_cmd().env("RUN_TEST_NEW_ENV", "123").output().unwrap();
let output = String::from_utf8_lossy(&result.stdout).to_string();
- assert!(output.contains("RUN_TEST_NEW_ENV=123"),
- "didn't find RUN_TEST_NEW_ENV inside of:\n\n{}", output);
+ assert!(
+ output.contains("RUN_TEST_NEW_ENV=123"),
+ "didn't find RUN_TEST_NEW_ENV inside of:\n\n{}",
+ output
+ );
}
#[test]
let output = String::from_utf8_lossy(&result.stdout).to_string();
- assert!(output.contains("RUN_TEST_NEW_ENV1=123"),
- "didn't find RUN_TEST_NEW_ENV1 inside of:\n\n{}", output);
- assert!(output.contains("RUN_TEST_NEW_ENV2=456"),
- "didn't find RUN_TEST_NEW_ENV2 inside of:\n\n{}", output);
+ assert!(
+ output.contains("RUN_TEST_NEW_ENV1=123"),
+ "didn't find RUN_TEST_NEW_ENV1 inside of:\n\n{}",
+ output
+ );
+ assert!(
+ output.contains("RUN_TEST_NEW_ENV2=456"),
+ "didn't find RUN_TEST_NEW_ENV2 inside of:\n\n{}",
+ output
+ );
}
// Regression tests for #30858.
extern "system" {
fn WaitForDebugEvent(lpDebugEvent: *mut DEBUG_EVENT, dwMilliseconds: DWORD) -> BOOL;
- fn ContinueDebugEvent(dwProcessId: DWORD, dwThreadId: DWORD,
- dwContinueStatus: DWORD) -> BOOL;
+ fn ContinueDebugEvent(
+ dwProcessId: DWORD,
+ dwThreadId: DWORD,
+ dwContinueStatus: DWORD,
+ ) -> BOOL;
}
const DEBUG_PROCESS: DWORD = 1;
let mut child = Command::new("cmd")
.creation_flags(DEBUG_PROCESS)
- .stdin(Stdio::piped()).spawn().unwrap();
+ .stdin(Stdio::piped())
+ .spawn()
+ .unwrap();
child.stdin.take().unwrap().write_all(b"exit\r\n").unwrap();
let mut events = 0;
- let mut event = DEBUG_EVENT {
- event_code: 0,
- process_id: 0,
- thread_id: 0,
- _junk: [0; 164],
- };
+ let mut event = DEBUG_EVENT { event_code: 0, process_id: 0, thread_id: 0, _junk: [0; 164] };
loop {
if unsafe { WaitForDebugEvent(&mut event as *mut DEBUG_EVENT, INFINITE) } == 0 {
panic!("WaitForDebugEvent failed!");
break;
}
- if unsafe { ContinueDebugEvent(event.process_id,
- event.thread_id,
- DBG_EXCEPTION_NOT_HANDLED) } == 0 {
+ if unsafe {
+ ContinueDebugEvent(event.process_id, event.thread_id, DBG_EXCEPTION_NOT_HANDLED)
+ } == 0
+ {
panic!("ContinueDebugEvent failed!");
}
}