diff options
| author | Ed Clarke <webmobster@gmail.com> | 2015-12-16 20:28:54 +0000 |
|---|---|---|
| committer | Ed Clarke <webmobster@gmail.com> | 2015-12-17 18:40:49 +0000 |
| commit | 21030f1fc9510d9808c0f8352ea8a5eeacfa4ca5 (patch) | |
| tree | 533c83e15b0e333c4d2b49deec5d2b299be230d6 /src/libstd/process.rs | |
| parent | d4ffaf6f836e6ff8260548041bd1dc9d8bd146f9 (diff) | |
| download | rust-21030f1fc9510d9808c0f8352ea8a5eeacfa4ca5.tar.gz rust-21030f1fc9510d9808c0f8352ea8a5eeacfa4ca5.zip | |
Add a debug implementation to process::Output
Diffstat (limited to 'src/libstd/process.rs')
| -rw-r--r-- | src/libstd/process.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/libstd/process.rs b/src/libstd/process.rs index 91c3819307f..be1fe9b2a9b 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -20,6 +20,7 @@ use ffi::OsStr; use fmt; use io::{self, Error, ErrorKind}; use path; +use str; use sys::pipe::{self, AnonPipe}; use sys::process as imp; use sys_common::{AsInner, AsInnerMut, FromInner, IntoInner}; @@ -400,6 +401,32 @@ pub struct Output { pub stderr: Vec<u8>, } +// If either stderr or stdout are valid utf8 strings it prints the valid +// strings, otherwise it prints the byte sequence instead +#[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: &fmt::Debug = match stdout_utf8 { + Ok(ref str) => str, + Err(_) => &self.stdout + }; + + let stderr_utf8 = str::from_utf8(&self.stderr); + let stderr_debug: &fmt::Debug = match stderr_utf8 { + Ok(ref str) => str, + Err(_) => &self.stderr + }; + + fmt.debug_struct("Output") + .field("status", &self.status) + .field("stdout", stdout_debug) + .field("stderr", stderr_debug) + .finish() + } +} + /// Describes what to do with a standard I/O stream for a child process. #[stable(feature = "process", since = "1.0.0")] pub struct Stdio(StdioImp); |
