Skip to content

Commit 67a2d1f

Browse files
committed
Auto merge of #30403 - webmobster:master, r=alexcrichton
I didn't see any reason that debug couldn't be added to this object, since every field derives debug.
2 parents 440ef8b + 21030f1 commit 67a2d1f

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/libstd/process.rs

+27
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use ffi::OsStr;
2020
use fmt;
2121
use io::{self, Error, ErrorKind};
2222
use path;
23+
use str;
2324
use sys::pipe::{self, AnonPipe};
2425
use sys::process as imp;
2526
use sys_common::{AsInner, AsInnerMut, FromInner, IntoInner};
@@ -400,6 +401,32 @@ pub struct Output {
400401
pub stderr: Vec<u8>,
401402
}
402403

404+
// If either stderr or stdout are valid utf8 strings it prints the valid
405+
// strings, otherwise it prints the byte sequence instead
406+
#[stable(feature = "process_output_debug", since = "1.7.0")]
407+
impl fmt::Debug for Output {
408+
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
409+
410+
let stdout_utf8 = str::from_utf8(&self.stdout);
411+
let stdout_debug: &fmt::Debug = match stdout_utf8 {
412+
Ok(ref str) => str,
413+
Err(_) => &self.stdout
414+
};
415+
416+
let stderr_utf8 = str::from_utf8(&self.stderr);
417+
let stderr_debug: &fmt::Debug = match stderr_utf8 {
418+
Ok(ref str) => str,
419+
Err(_) => &self.stderr
420+
};
421+
422+
fmt.debug_struct("Output")
423+
.field("status", &self.status)
424+
.field("stdout", stdout_debug)
425+
.field("stderr", stderr_debug)
426+
.finish()
427+
}
428+
}
429+
403430
/// Describes what to do with a standard I/O stream for a child process.
404431
#[stable(feature = "process", since = "1.0.0")]
405432
pub struct Stdio(StdioImp);

0 commit comments

Comments
 (0)