From 914b803429d8e83bdd5212b26049fe0bbbc6fc5e Mon Sep 17 00:00:00 2001 From: Ivan Petkov Date: Sat, 17 Jun 2017 16:40:21 -0700 Subject: [PATCH] process: Add `Debug` impls for nondeprecated structs --- src/lib.rs | 26 +++++++++++++++++++++++++- src/unix.rs | 13 +++++++++++++ src/windows.rs | 11 +++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index aa15624df..64798fca8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -115,6 +115,7 @@ //! `tokio_process::Child` is dropped. The behavior of the standard library can //! be regained with the `Child::forget` method. +#![warn(missing_debug_implementations)] #![deny(missing_docs)] #![doc(html_root_url = "https://docs.rs/tokio-process/0.1")] @@ -130,6 +131,7 @@ use std::process::{self, ExitStatus, Output, Stdio}; use futures::{Future, Poll, IntoFuture}; use futures::future::{Flatten, FutureResult, Either, ok}; +use std::fmt; use tokio_core::reactor::Handle; use tokio_io::io::{read_to_end}; use tokio_io::{AsyncWrite, AsyncRead, IoFuture}; @@ -261,6 +263,7 @@ impl CommandExt for process::Command { /// > done because futures in general take `drop` as a sign of cancellation, and /// > this `Child` is itself a future. If you'd like to run a process in the /// > background, though, you may use the `forget` method. +#[derive(Debug)] pub struct Child { child: imp::Child, kill_on_drop: bool, @@ -373,6 +376,14 @@ pub struct WaitWithOutput { inner: IoFuture, } +impl fmt::Debug for WaitWithOutput { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("WaitWithOutput") + .field("inner", &"..") + .finish() + } +} + impl Future for WaitWithOutput { type Item = Output; type Error = io::Error; @@ -387,6 +398,7 @@ impl Future for WaitWithOutput { /// This future is used to conveniently spawn a child and simply wait for its /// exit status. This future will resolves to the `ExitStatus` type in the /// standard library. +#[derive(Debug)] pub struct StatusAsync { inner: Flatten>, } @@ -409,6 +421,14 @@ pub struct OutputAsync { inner: IoFuture, } +impl fmt::Debug for OutputAsync { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("OutputAsync") + .field("inner", &"..") + .finish() + } +} + impl Future for OutputAsync { type Item = Output; type Error = io::Error; @@ -423,6 +443,7 @@ impl Future for OutputAsync { /// This type implements the `Write` trait to pass data to the stdin handle of /// a child process. Note that this type is also "futures aware" meaning that it /// is both (a) nonblocking and (b) will panic if used off of a future's task. +#[derive(Debug)] pub struct ChildStdin { inner: imp::ChildStdin, } @@ -433,6 +454,7 @@ pub struct ChildStdin { /// of a child process. Note that this type is also "futures aware" meaning /// that it is both (a) nonblocking and (b) will panic if used off of a /// future's task. +#[derive(Debug)] pub struct ChildStdout { inner: imp::ChildStdout, } @@ -443,6 +465,7 @@ pub struct ChildStdout { /// of a child process. Note that this type is also "futures aware" meaning /// that it is both (a) nonblocking and (b) will panic if used off of a /// future's task. +#[derive(Debug)] pub struct ChildStderr { inner: imp::ChildStderr, } @@ -485,6 +508,7 @@ impl AsyncRead for ChildStderr { #[deprecated(note = "use std::process::Command instead")] #[allow(deprecated, missing_docs)] +#[allow(deprecated, missing_debug_implementations, missing_docs)] #[doc(hidden)] pub struct Command { inner: process::Command, @@ -493,7 +517,7 @@ pub struct Command { } #[deprecated(note = "use std::process::Command instead")] -#[allow(deprecated, missing_docs)] +#[allow(deprecated, missing_debug_implementations, missing_docs)] #[doc(hidden)] pub struct Spawn { inner: Box>, diff --git a/src/unix.rs b/src/unix.rs index 47cec7b77..7e85a6017 100644 --- a/src/unix.rs +++ b/src/unix.rs @@ -36,6 +36,7 @@ use mio::event::Evented; use mio; use self::libc::c_int; use self::tokio_signal::unix::Signal; +use std::fmt; use tokio_io::IoFuture; use tokio_core::reactor::{Handle, PollEvented}; @@ -45,6 +46,17 @@ pub struct Child { sigchld: FlattenStream>, } +impl fmt::Debug for Child { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("Child") + .field("pid", &self.inner.id()) + .field("inner", &self.inner) + .field("reaped", &self.reaped) + .field("sigchld", &"..") + .finish() + } +} + impl Child { pub fn new(inner: process::Child, handle: &Handle) -> Child { Child { @@ -125,6 +137,7 @@ impl Child { } } +#[derive(Debug)] pub struct Fd(T); impl io::Read for Fd { diff --git a/src/windows.rs b/src/windows.rs index 4febf57f0..e87ece162 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -19,6 +19,7 @@ extern crate winapi; extern crate kernel32; extern crate mio_named_pipes; +use std::fmt; use std::io; use std::os::windows::prelude::*; use std::os::windows::process::ExitStatusExt; @@ -35,6 +36,16 @@ pub struct Child { waiting: Option, } +impl fmt::Debug for Child { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("Child") + .field("pid", &self.id()) + .field("child", &self.child) + .field("waiting", &"..") + .finish() + } +} + struct Waiting { rx: Fuse>, wait_object: winapi::HANDLE,