From 536ac262a126b6df30cb5e0d22eddda367e1276d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Sat, 28 Jun 2025 06:57:41 +1200 Subject: [PATCH 01/21] bump msrv to 86 for upcasting --- .github/workflows/test.yml | 2 +- Cargo.toml | 2 +- README.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dcc3e54..bc26987 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,7 +16,7 @@ jobs: - windows toolchain: - stable - - 1.77.0 + - 1.86.0 features: - tokio1 - std diff --git a/Cargo.toml b/Cargo.toml index 94e543e..5ca58f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ readme = "README.md" edition = "2021" exclude = ["/bin", "/.github"] -rust-version = "1.77.0" +rust-version = "1.86.0" [dependencies] futures = { version = "0.3.30", optional = true } diff --git a/README.md b/README.md index 1e540dd..cdeaa58 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ - **[API documentation][docs]**. - [Dual-licensed][copyright] with Apache 2.0 and MIT. - Successor to [command-group](https://github.com/watchexec/command-group). -- Minimum Supported Rust Version: 1.77.0. +- Minimum Supported Rust Version: 1.86.0. - Only the latest stable rustc version is supported. - MSRV increases will not incur major version bumps. From 7e1211080b4ff64b0187d898206f858a2ce7a750 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Sat, 28 Jun 2025 06:59:19 +1200 Subject: [PATCH 02/21] remove downcasting feature --- Cargo.toml | 3 --- src/generic_wrap.rs | 16 ---------------- src/tokio/core.rs | 2 -- 3 files changed, 21 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5ca58f6..920483d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,9 +41,6 @@ tokio = { version = "1.38.2", features = ["io-util", "macros", "process", "rt", [features] default = ["creation-flags", "job-object", "kill-on-drop", "process-group", "process-session", "tracing"] -## Enable Any trait bound on the ChildWrapper traits -downcasting = [] - ## Enable internal tracing logs tracing = ["dep:tracing"] diff --git a/src/generic_wrap.rs b/src/generic_wrap.rs index 6583c32..ce9c393 100644 --- a/src/generic_wrap.rs +++ b/src/generic_wrap.rs @@ -230,20 +230,4 @@ macro_rules! Wrap { }; } -macro_rules! MaybeAnyTrait { - ( - $(#[$($attrss:tt)*])* - $v:vis trait $name:ident $body:tt - ) => { - #[cfg(feature = "downcasting")] - $(#[$($attrss)*])* - $v trait $name: std::fmt::Debug + Send + Sync + std::any::Any $body - - #[cfg(not(feature = "downcasting"))] - $(#[$($attrss)*])* - $v trait $name: std::fmt::Debug + Send + Sync $body - } -} - -pub(crate) use MaybeAnyTrait; pub(crate) use Wrap; diff --git a/src/tokio/core.rs b/src/tokio/core.rs index 4806693..94b0ccb 100644 --- a/src/tokio/core.rs +++ b/src/tokio/core.rs @@ -24,7 +24,6 @@ crate::generic_wrap::Wrap!( |child| child ); -crate::generic_wrap::MaybeAnyTrait! { /// Wrapper for `tokio::process::Child`. /// /// This trait exposes most of the functionality of the underlying [`Child`]. It is implemented for @@ -213,7 +212,6 @@ pub trait TokioChildWrapper { } } } -} impl TokioChildWrapper for Child { fn inner(&self) -> &Child { From 4dae8abc00c186d81e9ed5eded020ecea474358c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Sat, 28 Jun 2025 07:05:03 +1200 Subject: [PATCH 03/21] fix unused controlflow warns --- src/tokio/job_object.rs | 4 ++-- src/tokio/process_group.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tokio/job_object.rs b/src/tokio/job_object.rs index ca7c804..2b56de3 100644 --- a/src/tokio/job_object.rs +++ b/src/tokio/job_object.rs @@ -161,14 +161,14 @@ impl TokioChildWrapper for JobObjectChild { let JobPort { completion_port, .. } = self.job_port; - spawn_blocking(move || wait_on_job(completion_port, None)).await??; + let _ = spawn_blocking(move || wait_on_job(completion_port, None)).await??; Ok(status) }) } #[cfg_attr(feature = "tracing", instrument(level = "debug", skip(self)))] fn try_wait(&mut self) -> Result> { - wait_on_job(self.job_port.completion_port, Some(Duration::ZERO))?; + let _ = wait_on_job(self.job_port.completion_port, Some(Duration::ZERO))?; self.inner.try_wait() } } diff --git a/src/tokio/process_group.rs b/src/tokio/process_group.rs index f01a9e2..d162f7d 100644 --- a/src/tokio/process_group.rs +++ b/src/tokio/process_group.rs @@ -201,7 +201,7 @@ impl TokioChildWrapper for ProcessGroupChild { // ...finally, if there are some that are still alive, // block in the background to reap them fully. - spawn_blocking(move || Self::wait_imp(pgid, WaitPidFlag::empty())).await??; + let _ = spawn_blocking(move || Self::wait_imp(pgid, WaitPidFlag::empty())).await??; Ok(status) }) } From 49c47ca4e59b30fe0c5532737390f5c517ebde92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Sat, 28 Jun 2025 07:13:08 +1200 Subject: [PATCH 04/21] change child wrapper inner()s to return one layer down --- src/tokio/core.rs | 114 ++++++++++++++++++++++++++++--------- src/tokio/job_object.rs | 18 +++--- src/tokio/process_group.rs | 18 +++--- 3 files changed, 103 insertions(+), 47 deletions(-) diff --git a/src/tokio/core.rs b/src/tokio/core.rs index 94b0ccb..44c9270 100644 --- a/src/tokio/core.rs +++ b/src/tokio/core.rs @@ -1,6 +1,8 @@ use std::{ + any::Any, future::Future, io::Result, + pin::Pin, process::{ExitStatus, Output}, }; @@ -46,32 +48,32 @@ crate::generic_wrap::Wrap!( /// pub struct YourChildWrapper(Child); /// /// impl TokioChildWrapper for YourChildWrapper { -/// fn inner(&self) -> &Child { +/// fn inner(&self) -> &dyn TokioChildWrapper { /// &self.0 /// } /// -/// fn inner_mut(&mut self) -> &mut Child { +/// fn inner_mut(&mut self) -> &mut dyn TokioChildWrapper { /// &mut self.0 /// } /// -/// fn into_inner(self: Box) -> Child { -/// (*self).0 +/// fn into_inner(self: Box) -> Box { +/// Box::new((*self).0) /// } /// } /// ``` -pub trait TokioChildWrapper { - /// Obtain a reference to the underlying `Child`. - fn inner(&self) -> &Child; +pub trait TokioChildWrapper: Any + std::fmt::Debug + Send { + /// Obtain a reference to the wrapped child. + fn inner(&self) -> &dyn TokioChildWrapper; - /// Obtain a mutable reference to the underlying `Child`. - fn inner_mut(&mut self) -> &mut Child; + /// Obtain a mutable reference to the wrapped child. + fn inner_mut(&mut self) -> &mut dyn TokioChildWrapper; - /// Consume the wrapper and return the underlying `Child`. + /// Consume the current wrapper and return the wrapped child. /// - /// Note that this may disrupt whatever the wrappers were doing. However, wrappers must ensure - /// that the `Child` is in a consistent state when this is called or they are dropped, so that - /// this is always safe. - fn into_inner(self: Box) -> Child; + /// Note that this may disrupt whatever the current wrapper was doing. However, wrappers must + /// ensure that the wrapped child is in a consistent state when this is called or they are + /// dropped, so that this is always safe. + fn into_inner(self: Box) -> Box; /// Obtain a clone if possible. /// @@ -83,23 +85,23 @@ pub trait TokioChildWrapper { /// Obtain the `Child`'s stdin. /// - /// By default this is a passthrough to the underlying `Child`. + /// By default this is a passthrough to the wrapped child. fn stdin(&mut self) -> &mut Option { - &mut self.inner_mut().stdin + self.inner_mut().stdin() } /// Obtain the `Child`'s stdout. /// - /// By default this is a passthrough to the underlying `Child`. + /// By default this is a passthrough to the wrapped child. fn stdout(&mut self) -> &mut Option { - &mut self.inner_mut().stdout + self.inner_mut().stdout() } /// Obtain the `Child`'s stderr. /// - /// By default this is a passthrough to the underlying `Child`. + /// By default this is a passthrough to the wrapped child. fn stderr(&mut self) -> &mut Option { - &mut self.inner_mut().stderr + self.inner_mut().stderr() } /// Obtain the `Child`'s process ID. @@ -120,7 +122,7 @@ pub trait TokioChildWrapper { fn kill(&mut self) -> Box> + Send + '_> { Box::new(async { self.start_kill()?; - Box::into_pin(self.wait()).await?; + self.wait().await?; Ok(()) }) } @@ -150,8 +152,8 @@ pub trait TokioChildWrapper { /// has exited will always return the same result. /// /// By default this is a passthrough to the underlying `Child`. - fn wait(&mut self) -> Box> + Send + '_> { - Box::new(self.inner_mut().wait()) + fn wait(&mut self) -> Pin> + Send + '_>> { + Box::pin(self.inner_mut().wait()) } /// Wait for the `Child` to exit and return its exit status and outputs. @@ -180,7 +182,7 @@ pub trait TokioChildWrapper { let stderr_fut = read_to_end(&mut stderr_pipe); let (status, stdout, stderr) = - try_join3(Box::into_pin(self.wait()), stdout_fut, stderr_fut).await?; + try_join3(self.wait(), stdout_fut, stderr_fut).await?; // Drop happens after `try_join` due to drop(stdout_pipe); @@ -214,13 +216,69 @@ pub trait TokioChildWrapper { } impl TokioChildWrapper for Child { - fn inner(&self) -> &Child { + fn inner(&self) -> &dyn TokioChildWrapper { self } - fn inner_mut(&mut self) -> &mut Child { + fn inner_mut(&mut self) -> &mut dyn TokioChildWrapper { self } - fn into_inner(self: Box) -> Child { - *self + fn into_inner(self: Box) -> Box { + Box::new(*self) + } + fn stdin(&mut self) -> &mut Option { + &mut self.stdin + } + fn stdout(&mut self) -> &mut Option { + &mut self.stdout + } + fn stderr(&mut self) -> &mut Option { + &mut self.stderr + } +} + +impl dyn TokioChildWrapper { + fn downcast_ref(&self) -> Option<&T> { + (self as &dyn Any).downcast_ref() + } + + fn is_raw_child(&self) -> bool { + self.downcast_ref::().is_some() + } + + /// Obtain a reference to the underlying [`Child`]. + pub fn inner_child(&self) -> &Child { + let mut inner = self; + while !inner.is_raw_child() { + inner = inner.inner(); + } + + // UNWRAP: we've just checked that it's Some with is_raw_child() + inner.downcast_ref().unwrap() + } + + /// Obtain a mutable reference to the underlying [`Child`]. + /// + /// Modifying the raw child may be unsound depending on the layering of wrappers. + pub unsafe fn inner_child_mut(&mut self) -> &mut Child { + let mut inner = self; + while !inner.is_raw_child() { + inner = inner.inner_mut(); + } + + // UNWRAP: we've just checked that with is_raw_child() + (inner as &mut dyn Any).downcast_mut().unwrap() + } + + /// Obtain the underlying [`Child`]. + /// + /// Unwrapping everything may be unsound depending on the state of the wrappers. + pub unsafe fn into_inner_child(self: Box) -> Child { + let mut inner = self; + while !inner.is_raw_child() { + inner = inner.into_inner(); + } + + // UNWRAP: we've just checked that with is_raw_child() + *(inner as Box).downcast().unwrap() } } diff --git a/src/tokio/job_object.rs b/src/tokio/job_object.rs index 2b56de3..9e1322f 100644 --- a/src/tokio/job_object.rs +++ b/src/tokio/job_object.rs @@ -1,7 +1,7 @@ -use std::{future::Future, io::Result, process::ExitStatus, time::Duration}; +use std::{future::Future, io::Result, pin::Pin, process::ExitStatus, time::Duration}; use tokio::{ - process::{Child, Command}, + process::Command, task::spawn_blocking, }; #[cfg(feature = "tracing")] @@ -78,7 +78,7 @@ impl TokioCommandWrapper for JobObject { let handle = HANDLE( inner - .inner() + .inner_child() .raw_handle() .expect("child has exited but it has not even started") as _, ); @@ -114,13 +114,13 @@ impl JobObjectChild { } impl TokioChildWrapper for JobObjectChild { - fn inner(&self) -> &Child { + fn inner(&self) -> &dyn TokioChildWrapper { self.inner.inner() } - fn inner_mut(&mut self) -> &mut Child { + fn inner_mut(&mut self) -> &mut dyn TokioChildWrapper { self.inner.inner_mut() } - fn into_inner(self: Box) -> Child { + fn into_inner(self: Box) -> Box { // manually drop the completion port let its = std::mem::ManuallyDrop::new(self.job_port); unsafe { CloseHandle(its.completion_port.0) }.ok(); @@ -136,8 +136,8 @@ impl TokioChildWrapper for JobObjectChild { } #[cfg_attr(feature = "tracing", instrument(level = "debug", skip(self)))] - fn wait(&mut self) -> Box> + Send + '_> { - Box::new(async { + fn wait(&mut self) -> Pin> + Send + '_>> { + Box::pin(async { if let ChildExitStatus::Exited(status) = &self.exit_status { return Ok(*status); } @@ -146,7 +146,7 @@ impl TokioChildWrapper for JobObjectChild { // always wait for parent to exit first, as by the time it does, // it's likely that all its children have already exited. - let status = Box::into_pin(self.inner.wait()).await?; + let status = self.inner.wait().await?; self.exit_status = ChildExitStatus::Exited(status); // nevertheless, now try reaping all children a few times... diff --git a/src/tokio/process_group.rs b/src/tokio/process_group.rs index d162f7d..6b45255 100644 --- a/src/tokio/process_group.rs +++ b/src/tokio/process_group.rs @@ -3,6 +3,7 @@ use std::{ io::{Error, Result}, ops::ControlFlow, os::unix::process::ExitStatusExt, + pin::Pin, process::ExitStatus, }; @@ -15,10 +16,7 @@ use nix::{ }, unistd::Pid, }; -use tokio::{ - process::{Child, Command}, - task::spawn_blocking, -}; +use tokio::{process::Command, task::spawn_blocking}; #[cfg(feature = "tracing")] use tracing::instrument; @@ -162,13 +160,13 @@ impl ProcessGroupChild { } impl TokioChildWrapper for ProcessGroupChild { - fn inner(&self) -> &Child { + fn inner(&self) -> &dyn TokioChildWrapper { self.inner.inner() } - fn inner_mut(&mut self) -> &mut Child { + fn inner_mut(&mut self) -> &mut dyn TokioChildWrapper { self.inner.inner_mut() } - fn into_inner(self: Box) -> Child { + fn into_inner(self: Box) -> Box { self.inner.into_inner() } @@ -178,8 +176,8 @@ impl TokioChildWrapper for ProcessGroupChild { } #[cfg_attr(feature = "tracing", instrument(level = "debug", skip(self)))] - fn wait(&mut self) -> Box> + Send + '_> { - Box::new(async { + fn wait(&mut self) -> Pin> + Send + '_>> { + Box::pin(async { if let ChildExitStatus::Exited(status) = &self.exit_status { return Ok(*status); } @@ -189,7 +187,7 @@ impl TokioChildWrapper for ProcessGroupChild { // always wait for parent to exit first, as by the time it does, // it's likely that all its children have already been reaped. - let status = Box::into_pin(self.inner.wait()).await?; + let status = self.inner.wait().await?; self.exit_status = ChildExitStatus::Exited(status); // nevertheless, now try reaping all children a few times... From 1a6f94c077dbf3a8db7dbe15e384f23fb77becab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Sat, 28 Jun 2025 07:32:51 +1200 Subject: [PATCH 05/21] impl for std --- src/std/core.rs | 114 +++++++++++++++++++++++++++++---------- src/std/job_object.rs | 10 ++-- src/std/process_group.rs | 10 ++-- 3 files changed, 96 insertions(+), 38 deletions(-) diff --git a/src/std/core.rs b/src/std/core.rs index e5ec4e6..d6e63c0 100644 --- a/src/std/core.rs +++ b/src/std/core.rs @@ -1,4 +1,5 @@ use std::{ + any::Any, io::{Read, Result}, process::{Child, ChildStderr, ChildStdin, ChildStdout, Command, ExitStatus, Output}, }; @@ -18,7 +19,6 @@ crate::generic_wrap::Wrap!( StdChild // |child| StdChild(child) ); -crate::generic_wrap::MaybeAnyTrait! { /// Wrapper for `std::process::Child`. /// /// This trait exposes most of the functionality of the underlying [`Child`]. It is implemented for @@ -42,32 +42,32 @@ crate::generic_wrap::MaybeAnyTrait! { /// pub struct YourChildWrapper(Child); /// /// impl StdChildWrapper for YourChildWrapper { -/// fn inner(&self) -> &Child { +/// fn inner(&self) -> &dyn StdChildWrapper { /// &self.0 /// } /// -/// fn inner_mut(&mut self) -> &mut Child { +/// fn inner_mut(&mut self) -> &mut dyn StdChildWrapper { /// &mut self.0 /// } /// -/// fn into_inner(self: Box) -> Child { -/// (*self).0 +/// fn into_inner(self: Box) -> Box { +/// Box::new((*self).0) /// } /// } /// ``` -pub trait StdChildWrapper { - /// Obtain a reference to the underlying `Child`. - fn inner(&self) -> &Child; +pub trait StdChildWrapper: Any + std::fmt::Debug + Send { + /// Obtain a reference to the wrapped child. + fn inner(&self) -> &dyn StdChildWrapper; - /// Obtain a mutable reference to the underlying `Child`. - fn inner_mut(&mut self) -> &mut Child; + /// Obtain a mutable reference to the wrapped child. + fn inner_mut(&mut self) -> &mut dyn StdChildWrapper; - /// Consume the wrapper and return the underlying `Child`. + /// Consume the current wrapper and return the wrapped child. /// - /// Note that this may disrupt whatever the wrappers were doing. However, wrappers must ensure - /// that the `Child` is in a consistent state when this is called or they are dropped, so that - /// this is always safe. - fn into_inner(self: Box) -> Child; + /// Note that this may disrupt whatever the current wrapper was doing. However, wrappers must + /// ensure that the wrapped child is in a consistent state when this is called or they are + /// dropped, so that this is always safe. + fn into_inner(self: Box) -> Box; /// Obtain a clone if possible. /// @@ -79,23 +79,23 @@ pub trait StdChildWrapper { /// Obtain the `Child`'s stdin. /// - /// By default this is a passthrough to the underlying `Child`. + /// By default this is a passthrough to the wrapped child. fn stdin(&mut self) -> &mut Option { - &mut self.inner_mut().stdin + self.inner_mut().stdin() } /// Obtain the `Child`'s stdout. /// - /// By default this is a passthrough to the underlying `Child`. + /// By default this is a passthrough to the wrapped child. fn stdout(&mut self) -> &mut Option { - &mut self.inner_mut().stdout + self.inner_mut().stdout() } /// Obtain the `Child`'s stderr. /// - /// By default this is a passthrough to the underlying `Child`. + /// By default this is a passthrough to the wrapped child. fn stderr(&mut self) -> &mut Option { - &mut self.inner_mut().stderr + self.inner_mut().stderr() } /// Obtain the `Child`'s process ID. @@ -212,7 +212,6 @@ pub trait StdChildWrapper { .map_err(std::io::Error::from) } } -} /// A thin wrapper around [`Child`]. /// @@ -223,14 +222,73 @@ pub trait StdChildWrapper { pub struct StdChild(pub Child); impl StdChildWrapper for StdChild { - fn inner(&self) -> &Child { - &self.0 + fn inner(&self) -> &dyn StdChildWrapper { + self } - fn inner_mut(&mut self) -> &mut Child { - &mut self.0 + fn inner_mut(&mut self) -> &mut dyn StdChildWrapper { + self } - fn into_inner(self: Box) -> Child { - (*self).0 + fn into_inner(self: Box) -> Box { + self + } + fn stdin(&mut self) -> &mut Option { + &mut self.0.stdin + } + fn stdout(&mut self) -> &mut Option { + &mut self.0.stdout + } + fn stderr(&mut self) -> &mut Option { + &mut self.0.stderr + } +} + +impl dyn StdChildWrapper { + fn downcast_ref(&self) -> Option<&T> { + (self as &dyn Any).downcast_ref() + } + + fn is_raw_child(&self) -> bool { + self.downcast_ref::().is_some() + } + + /// Obtain a reference to the underlying [`Child`]. + pub fn inner_child(&self) -> &Child { + let mut inner = self; + while !inner.is_raw_child() { + inner = inner.inner(); + } + + // UNWRAP: we've just checked that it's Some with is_raw_child() + &inner.downcast_ref::().unwrap().0 + } + + /// Obtain a mutable reference to the underlying [`Child`]. + /// + /// Modifying the raw child may be unsound depending on the layering of wrappers. + pub unsafe fn inner_child_mut(&mut self) -> &mut Child { + let mut inner = self; + while !inner.is_raw_child() { + inner = inner.inner_mut(); + } + + // UNWRAP: we've just checked that with is_raw_child() + &mut (inner as &mut dyn Any) + .downcast_mut::() + .unwrap() + .0 + } + + /// Obtain the underlying [`Child`]. + /// + /// Unwrapping everything may be unsound depending on the state of the wrappers. + pub unsafe fn into_inner_child(self: Box) -> Child { + let mut inner = self; + while !inner.is_raw_child() { + inner = inner.into_inner(); + } + + // UNWRAP: we've just checked that with is_raw_child() + (inner as Box).downcast::().unwrap().0 } } diff --git a/src/std/job_object.rs b/src/std/job_object.rs index 574de65..8c7bc47 100644 --- a/src/std/job_object.rs +++ b/src/std/job_object.rs @@ -1,7 +1,7 @@ use std::{ io::Result, os::windows::{io::AsRawHandle, process::CommandExt}, - process::{Child, Command, ExitStatus}, + process::{Command, ExitStatus}, time::Duration, }; @@ -66,7 +66,7 @@ impl StdCommandWrapper for JobObject { #[cfg(feature = "tracing")] debug!(?create_suspended, "options from other wrappers"); - let handle = HANDLE(inner.inner().as_raw_handle() as _); + let handle = HANDLE(inner.inner_child().as_raw_handle() as _); let job_port = make_job_object(handle, false)?; @@ -99,13 +99,13 @@ impl JobObjectChild { } impl StdChildWrapper for JobObjectChild { - fn inner(&self) -> &Child { + fn inner(&self) -> &dyn StdChildWrapper { self.inner.inner() } - fn inner_mut(&mut self) -> &mut Child { + fn inner_mut(&mut self) -> &mut dyn StdChildWrapper { self.inner.inner_mut() } - fn into_inner(self: Box) -> Child { + fn into_inner(self: Box) -> Box { // manually drop the completion port let its = std::mem::ManuallyDrop::new(self.job_port); unsafe { CloseHandle(its.completion_port.0) }.ok(); diff --git a/src/std/process_group.rs b/src/std/process_group.rs index ff94518..d34356d 100644 --- a/src/std/process_group.rs +++ b/src/std/process_group.rs @@ -2,7 +2,7 @@ use std::{ io::{Error, Result}, ops::ControlFlow, os::unix::process::{CommandExt, ExitStatusExt}, - process::{Child, Command, ExitStatus}, + process::{Command, ExitStatus}, }; use nix::{ @@ -150,13 +150,13 @@ impl ProcessGroupChild { } impl StdChildWrapper for ProcessGroupChild { - fn inner(&self) -> &Child { + fn inner(&self) -> &dyn StdChildWrapper { self.inner.inner() } - fn inner_mut(&mut self) -> &mut Child { + fn inner_mut(&mut self) -> &mut dyn StdChildWrapper { self.inner.inner_mut() } - fn into_inner(self: Box) -> Child { + fn into_inner(self: Box) -> Box { self.inner.into_inner() } @@ -177,7 +177,7 @@ impl StdChildWrapper for ProcessGroupChild { self.exit_status = ChildExitStatus::Exited(status); // nevertheless, now wait and make sure we reap all children. - Self::wait_imp(self.pgid, WaitPidFlag::empty())?; + let _ = Self::wait_imp(self.pgid, WaitPidFlag::empty())?; Ok(status) } From 31a40b7d36b55acb64b924278df0e28e64134802 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Sat, 28 Jun 2025 07:34:13 +1200 Subject: [PATCH 06/21] fmt --- src/tokio/core.rs | 7 +++---- src/tokio/job_object.rs | 5 +---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/tokio/core.rs b/src/tokio/core.rs index 44c9270..49b3b86 100644 --- a/src/tokio/core.rs +++ b/src/tokio/core.rs @@ -181,8 +181,7 @@ pub trait TokioChildWrapper: Any + std::fmt::Debug + Send { let stdout_fut = read_to_end(&mut stdout_pipe); let stderr_fut = read_to_end(&mut stderr_pipe); - let (status, stdout, stderr) = - try_join3(self.wait(), stdout_fut, stderr_fut).await?; + let (status, stdout, stderr) = try_join3(self.wait(), stdout_fut, stderr_fut).await?; // Drop happens after `try_join` due to drop(stdout_pipe); @@ -238,8 +237,8 @@ impl TokioChildWrapper for Child { impl dyn TokioChildWrapper { fn downcast_ref(&self) -> Option<&T> { - (self as &dyn Any).downcast_ref() - } + (self as &dyn Any).downcast_ref() + } fn is_raw_child(&self) -> bool { self.downcast_ref::().is_some() diff --git a/src/tokio/job_object.rs b/src/tokio/job_object.rs index 9e1322f..a5cf64a 100644 --- a/src/tokio/job_object.rs +++ b/src/tokio/job_object.rs @@ -1,9 +1,6 @@ use std::{future::Future, io::Result, pin::Pin, process::ExitStatus, time::Duration}; -use tokio::{ - process::Command, - task::spawn_blocking, -}; +use tokio::{process::Command, task::spawn_blocking}; #[cfg(feature = "tracing")] use tracing::{debug, instrument}; use windows::Win32::{ From ee807252f1b99fa51aea108ad93c2553f0f78da8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Sat, 28 Jun 2025 07:36:09 +1200 Subject: [PATCH 07/21] fix test check --- tests/std_unix/into_inner_write_stdin.rs | 40 ++++++++++++++---------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/tests/std_unix/into_inner_write_stdin.rs b/tests/std_unix/into_inner_write_stdin.rs index 79a430b..d133e12 100644 --- a/tests/std_unix/into_inner_write_stdin.rs +++ b/tests/std_unix/into_inner_write_stdin.rs @@ -2,11 +2,13 @@ use super::prelude::*; #[test] fn nowrap() -> Result<()> { - let mut child = StdCommandWrap::with_new("cat", |command| { - command.stdin(Stdio::piped()).stdout(Stdio::piped()); - }) - .spawn()? - .into_inner(); + let mut child = unsafe { + StdCommandWrap::with_new("cat", |command| { + command.stdin(Stdio::piped()).stdout(Stdio::piped()); + }) + .spawn()? + .into_inner_child() + }; if let Some(mut din) = child.stdin.take() { din.write_all(b"hello")?; @@ -23,12 +25,14 @@ fn nowrap() -> Result<()> { #[test] fn process_group() -> Result<()> { - let mut child = StdCommandWrap::with_new("cat", |command| { - command.stdin(Stdio::piped()).stdout(Stdio::piped()); - }) - .wrap(ProcessGroup::leader()) - .spawn()? - .into_inner(); + let mut child = unsafe { + StdCommandWrap::with_new("cat", |command| { + command.stdin(Stdio::piped()).stdout(Stdio::piped()); + }) + .wrap(ProcessGroup::leader()) + .spawn()? + .into_inner_child() + }; if let Some(mut din) = child.stdin.take() { din.write_all(b"hello")?; @@ -45,12 +49,14 @@ fn process_group() -> Result<()> { #[test] fn process_session() -> Result<()> { - let mut child = StdCommandWrap::with_new("cat", |command| { - command.stdin(Stdio::piped()).stdout(Stdio::piped()); - }) - .wrap(ProcessSession) - .spawn()? - .into_inner(); + let mut child = unsafe { + StdCommandWrap::with_new("cat", |command| { + command.stdin(Stdio::piped()).stdout(Stdio::piped()); + }) + .wrap(ProcessSession) + .spawn()? + .into_inner_child() + }; if let Some(mut din) = child.stdin.take() { din.write_all(b"hello")?; From 37b2b15708f0d933e769c4bb569b3f3713d987c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Sat, 28 Jun 2025 17:11:50 +1200 Subject: [PATCH 08/21] implement necessary things for std --- src/std/core.rs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/std/core.rs b/src/std/core.rs index d6e63c0..910e028 100644 --- a/src/std/core.rs +++ b/src/std/core.rs @@ -205,11 +205,7 @@ pub trait StdChildWrapper: Any + std::fmt::Debug + Send { /// and unwrapped processes. #[cfg(unix)] fn signal(&self, sig: i32) -> Result<()> { - kill( - Pid::from_raw(i32::try_from(self.id()).map_err(std::io::Error::other)?), - Signal::try_from(sig)?, - ) - .map_err(std::io::Error::from) + self.inner().signal(sig) } } @@ -240,6 +236,23 @@ impl StdChildWrapper for StdChild { fn stderr(&mut self) -> &mut Option { &mut self.0.stderr } + fn id(&self) -> u32 { + self.0.id() + } + fn try_wait(&mut self) -> Result> { + self.0.try_wait() + } + fn wait(&mut self) -> Result { + self.0.wait() + } + #[cfg(unix)] + fn signal(&self, sig: i32) -> Result<()> { + kill( + Pid::from_raw(i32::try_from(self.id()).map_err(std::io::Error::other)?), + Signal::try_from(sig)?, + ) + .map_err(std::io::Error::from) + } } impl dyn StdChildWrapper { From ed88fc6d9d389e8dadf81ffb9b69d0a6a537c1d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Sat, 28 Jun 2025 17:15:41 +1200 Subject: [PATCH 09/21] implement necessary things for tokio --- src/tokio/core.rs | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/src/tokio/core.rs b/src/tokio/core.rs index 49b3b86..9271a28 100644 --- a/src/tokio/core.rs +++ b/src/tokio/core.rs @@ -202,15 +202,7 @@ pub trait TokioChildWrapper: Any + std::fmt::Debug + Send { /// and unwrapped processes. #[cfg(unix)] fn signal(&self, sig: i32) -> Result<()> { - if let Some(id) = self.id() { - kill( - Pid::from_raw(i32::try_from(id).map_err(std::io::Error::other)?), - Signal::try_from(sig)?, - ) - .map_err(std::io::Error::from) - } else { - Ok(()) - } + self.inner().signal(sig) } } @@ -233,6 +225,30 @@ impl TokioChildWrapper for Child { fn stderr(&mut self) -> &mut Option { &mut self.stderr } + fn id(&self) -> Option { + self.id() + } + fn start_kill(&mut self) -> Result<()> { + self.start_kill() + } + fn try_wait(&mut self) -> Result> { + self.try_wait() + } + fn wait(&mut self) -> Pin> + Send + '_>> { + Box::pin(self.wait()) + } + #[cfg(unix)] + fn signal(&self, sig: i32) -> Result<()> { + if let Some(id) = self.id() { + kill( + Pid::from_raw(i32::try_from(id).map_err(std::io::Error::other)?), + Signal::try_from(sig)?, + ) + .map_err(std::io::Error::from) + } else { + Ok(()) + } + } } impl dyn TokioChildWrapper { From f32b5f507ab13cac39e894ab1769b524b46eec11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Sat, 28 Jun 2025 19:16:27 +1200 Subject: [PATCH 10/21] fix tests --- src/std/core.rs | 3 +-- tests/tokio_unix/kill_and_try_wait.rs | 2 +- tests/tokio_unix/multiproc_linux.rs | 4 ++-- tests/tokio_unix/wait_after_die.rs | 6 +++--- tests/tokio_unix/wait_twice.rs | 12 ++++++------ tests/tokio_unix/wait_twice_after_sigterm.rs | 12 ++++++------ 6 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/std/core.rs b/src/std/core.rs index 910e028..e5dbe4e 100644 --- a/src/std/core.rs +++ b/src/std/core.rs @@ -36,10 +36,9 @@ crate::generic_wrap::Wrap!( /// /// ```rust /// use process_wrap::std::*; -/// use std::process::Child; /// /// #[derive(Debug)] -/// pub struct YourChildWrapper(Child); +/// pub struct YourChildWrapper(StdChild); /// /// impl StdChildWrapper for YourChildWrapper { /// fn inner(&self) -> &dyn StdChildWrapper { diff --git a/tests/tokio_unix/kill_and_try_wait.rs b/tests/tokio_unix/kill_and_try_wait.rs index fce83ba..2c25466 100644 --- a/tests/tokio_unix/kill_and_try_wait.rs +++ b/tests/tokio_unix/kill_and_try_wait.rs @@ -29,7 +29,7 @@ async fn process_group() -> Result<()> { Box::into_pin(child.kill()).await?; - let status = Box::into_pin(child.wait()).await?; + let status = child.wait().await?; assert!(!status.success()); sleep(DIE_TIME).await; diff --git a/tests/tokio_unix/multiproc_linux.rs b/tests/tokio_unix/multiproc_linux.rs index 89dc029..fa41499 100644 --- a/tests/tokio_unix/multiproc_linux.rs +++ b/tests/tokio_unix/multiproc_linux.rs @@ -83,7 +83,7 @@ async fn process_group_kill_group() -> Result<()> { nix::sys::signal::killpg(nix::unistd::Pid::from_raw(parent), Signal::SIGKILL).unwrap(); sleep(DIE_TIME).await; assert!(!pid_alive(child), "child process should be dead"); - Box::into_pin(leader.wait()).await.unwrap(); + leader.wait().await.unwrap(); assert!(!pid_alive(parent), "parent process should be dead"); Ok(()) @@ -170,7 +170,7 @@ async fn process_session_kill_group() -> Result<()> { nix::sys::signal::killpg(nix::unistd::Pid::from_raw(parent), Signal::SIGKILL).unwrap(); sleep(DIE_TIME).await; assert!(!pid_alive(child), "child process should be dead"); - Box::into_pin(leader.wait()).await.unwrap(); + leader.wait().await.unwrap(); assert!(!pid_alive(parent), "parent process should be dead"); Ok(()) diff --git a/tests/tokio_unix/wait_after_die.rs b/tests/tokio_unix/wait_after_die.rs index c197cdf..f1c85f7 100644 --- a/tests/tokio_unix/wait_after_die.rs +++ b/tests/tokio_unix/wait_after_die.rs @@ -8,7 +8,7 @@ async fn nowrap() -> Result<()> { .spawn()?; sleep(DIE_TIME).await; - let status = Box::into_pin(child.wait()).await?; + let status = child.wait().await?; assert!(status.success()); Ok(()) @@ -23,7 +23,7 @@ async fn process_group() -> Result<()> { .spawn()?; sleep(DIE_TIME).await; - let status = Box::into_pin(child.wait()).await?; + let status = child.wait().await?; assert!(status.success()); Ok(()) @@ -38,7 +38,7 @@ async fn process_session() -> Result<()> { .spawn()?; sleep(DIE_TIME).await; - let status = Box::into_pin(child.wait()).await?; + let status = child.wait().await?; assert!(status.success()); Ok(()) diff --git a/tests/tokio_unix/wait_twice.rs b/tests/tokio_unix/wait_twice.rs index 40461f2..3560cb4 100644 --- a/tests/tokio_unix/wait_twice.rs +++ b/tests/tokio_unix/wait_twice.rs @@ -7,10 +7,10 @@ async fn nowrap() -> Result<()> { }) .spawn()?; - let status = Box::into_pin(child.wait()).await?; + let status = child.wait().await?; assert!(status.success()); - let status = Box::into_pin(child.wait()).await?; + let status = child.wait().await?; assert!(status.success()); Ok(()) @@ -24,10 +24,10 @@ async fn process_group() -> Result<()> { .wrap(ProcessGroup::leader()) .spawn()?; - let status = Box::into_pin(child.wait()).await?; + let status = child.wait().await?; assert!(status.success()); - let status = Box::into_pin(child.wait()).await?; + let status = child.wait().await?; assert!(status.success()); Ok(()) @@ -41,10 +41,10 @@ async fn process_session() -> Result<()> { .wrap(ProcessSession) .spawn()?; - let status = Box::into_pin(child.wait()).await?; + let status = child.wait().await?; assert!(status.success()); - let status = Box::into_pin(child.wait()).await?; + let status = child.wait().await?; assert!(status.success()); Ok(()) diff --git a/tests/tokio_unix/wait_twice_after_sigterm.rs b/tests/tokio_unix/wait_twice_after_sigterm.rs index 2b2e7d7..e72b4a9 100644 --- a/tests/tokio_unix/wait_twice_after_sigterm.rs +++ b/tests/tokio_unix/wait_twice_after_sigterm.rs @@ -10,10 +10,10 @@ async fn nowrap() -> Result<()> { child.signal(Signal::SIGTERM as _)?; - let status = Box::into_pin(child.wait()).await?; + let status = child.wait().await?; assert_eq!(status.signal(), Some(Signal::SIGTERM as i32), "wait() one"); - let status = Box::into_pin(child.wait()).await?; + let status = child.wait().await?; assert_eq!(status.signal(), Some(Signal::SIGTERM as i32), "wait() two"); Ok(()) @@ -30,10 +30,10 @@ async fn process_group() -> Result<()> { child.signal(Signal::SIGTERM as _)?; - let status = Box::into_pin(child.wait()).await?; + let status = child.wait().await?; assert_eq!(status.signal(), Some(Signal::SIGTERM as i32), "wait() one"); - let status = Box::into_pin(child.wait()).await?; + let status = child.wait().await?; assert_eq!(status.signal(), Some(Signal::SIGTERM as i32), "wait() two"); Ok(()) @@ -50,10 +50,10 @@ async fn process_session() -> Result<()> { child.signal(Signal::SIGTERM as _)?; - let status = Box::into_pin(child.wait()).await?; + let status = child.wait().await?; assert_eq!(status.signal(), Some(Signal::SIGTERM as i32), "wait() one"); - let status = Box::into_pin(child.wait()).await?; + let status = child.wait().await?; assert_eq!(status.signal(), Some(Signal::SIGTERM as i32), "wait() two"); Ok(()) From 670725561b31406ad6a2cdf263f8d017e39f3575 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Sat, 28 Jun 2025 19:19:11 +1200 Subject: [PATCH 11/21] fix windows tests --- src/std/job_object.rs | 4 ++-- tests/std_windows/into_inner_write_stdin.rs | 8 ++++---- tests/tokio_windows/wait_after_die.rs | 4 ++-- tests/tokio_windows/wait_twice.rs | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/std/job_object.rs b/src/std/job_object.rs index 8c7bc47..f557e97 100644 --- a/src/std/job_object.rs +++ b/src/std/job_object.rs @@ -135,13 +135,13 @@ impl StdChildWrapper for JobObjectChild { let JobPort { completion_port, .. } = self.job_port; - wait_on_job(completion_port, None)?; + let _ = wait_on_job(completion_port, None)?; Ok(status) } #[cfg_attr(feature = "tracing", instrument(level = "debug", skip(self)))] fn try_wait(&mut self) -> Result> { - wait_on_job(self.job_port.completion_port, Some(Duration::ZERO))?; + let _ = wait_on_job(self.job_port.completion_port, Some(Duration::ZERO))?; self.inner.try_wait() } } diff --git a/tests/std_windows/into_inner_write_stdin.rs b/tests/std_windows/into_inner_write_stdin.rs index ff7ade9..d19f74d 100644 --- a/tests/std_windows/into_inner_write_stdin.rs +++ b/tests/std_windows/into_inner_write_stdin.rs @@ -11,12 +11,12 @@ fn nowrap() -> Result<()> { .spawn()? .into_inner(); - if let Some(mut din) = child.stdin.take() { + if let Some(mut din) = child.stdin().take() { din.write_all(b"hello")?; } let mut output = String::new(); - if let Some(mut out) = child.stdout.take() { + if let Some(mut out) = child.stdout().take() { out.read_to_string(&mut output)?; } @@ -36,12 +36,12 @@ fn job_object() -> Result<()> { .spawn()? .into_inner(); - if let Some(mut din) = child.stdin.take() { + if let Some(mut din) = child.stdin().take() { din.write_all(b"hello")?; } let mut output = String::new(); - if let Some(mut out) = child.stdout.take() { + if let Some(mut out) = child.stdout().take() { out.read_to_string(&mut output)?; } diff --git a/tests/tokio_windows/wait_after_die.rs b/tests/tokio_windows/wait_after_die.rs index 2a91f7d..0b1f840 100644 --- a/tests/tokio_windows/wait_after_die.rs +++ b/tests/tokio_windows/wait_after_die.rs @@ -8,7 +8,7 @@ async fn nowrap() -> Result<()> { .spawn()?; sleep(DIE_TIME).await; - let status = Box::into_pin(child.wait()).await?; + let status = child.wait().await?; assert!(status.success()); Ok(()) @@ -23,7 +23,7 @@ async fn job_object() -> Result<()> { .spawn()?; sleep(DIE_TIME).await; - let status = Box::into_pin(child.wait()).await?; + let status = child.wait().await?; assert!(status.success()); Ok(()) diff --git a/tests/tokio_windows/wait_twice.rs b/tests/tokio_windows/wait_twice.rs index a89c7f4..c79e9e6 100644 --- a/tests/tokio_windows/wait_twice.rs +++ b/tests/tokio_windows/wait_twice.rs @@ -7,10 +7,10 @@ async fn nowrap() -> Result<()> { }) .spawn()?; - let status = Box::into_pin(child.wait()).await?; + let status = child.wait().await?; assert!(status.success()); - let status = Box::into_pin(child.wait()).await?; + let status = child.wait().await?; assert!(status.success()); Ok(()) @@ -24,10 +24,10 @@ async fn job_object() -> Result<()> { .wrap(JobObject) .spawn()?; - let status = Box::into_pin(child.wait()).await?; + let status = child.wait().await?; assert!(status.success()); - let status = Box::into_pin(child.wait()).await?; + let status = child.wait().await?; assert!(status.success()); Ok(()) From f9cc613628bfad81c4f30fd1078857689c7c982a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Sat, 28 Jun 2025 21:09:33 +1200 Subject: [PATCH 12/21] no longer need StdChild wrapper --- src/std.rs | 2 +- src/std/core.rs | 48 +++++++++++++++++++----------------------------- 2 files changed, 20 insertions(+), 30 deletions(-) diff --git a/src/std.rs b/src/std.rs index 89d15d3..f3e30fd 100644 --- a/src/std.rs +++ b/src/std.rs @@ -9,7 +9,7 @@ //! ``` #[doc(inline)] -pub use core::{StdChild, StdChildWrapper, StdCommandWrap, StdCommandWrapper}; +pub use core::{StdChildWrapper, StdCommandWrap, StdCommandWrapper}; #[cfg(all(windows, feature = "creation-flags"))] #[doc(inline)] pub use creation_flags::CreationFlags; diff --git a/src/std/core.rs b/src/std/core.rs index e5dbe4e..3de386a 100644 --- a/src/std/core.rs +++ b/src/std/core.rs @@ -16,29 +16,30 @@ crate::generic_wrap::Wrap!( StdCommandWrapper, Child, StdChildWrapper, - StdChild // |child| StdChild(child) + |child| child ); /// Wrapper for `std::process::Child`. /// /// This trait exposes most of the functionality of the underlying [`Child`]. It is implemented for -/// [`StdChild`] (a thin wrapper around [`Child`]) (because implementing directly on [`Child`] would -/// loop) and by wrappers. +/// [`Child`] and by wrappers. /// /// The required methods are `inner`, `inner_mut`, and `into_inner`. That provides access to the -/// underlying `Child` and allows the wrapper to be dropped and the `Child` to be used directly if -/// necessary. +/// lower layer and ultimately allows the wrappers to be unwrap and the `Child` to be used directly +/// if necessary. There are convenience `inner_child`, `inner_child_mut` and `into_inner_child` +/// methods on the trait object. /// /// It also makes it possible for all the other methods to have default implementations. Some are -/// direct passthroughs to the underlying `Child`, while others are more complex. +/// direct passthroughs to the lower layers, while others are more complex. /// /// Here's a simple example of a wrapper: /// /// ```rust /// use process_wrap::std::*; +/// use std::process::Child; /// /// #[derive(Debug)] -/// pub struct YourChildWrapper(StdChild); +/// pub struct YourChildWrapper(Child); /// /// impl StdChildWrapper for YourChildWrapper { /// fn inner(&self) -> &dyn StdChildWrapper { @@ -208,15 +209,7 @@ pub trait StdChildWrapper: Any + std::fmt::Debug + Send { } } -/// A thin wrapper around [`Child`]. -/// -/// This is used only because implementing [`StdChildWrapper`] directly on std's [`Child`] creates -/// loops in the type system. It is not intended to be used directly, but only to be used internally -/// by the library. -#[derive(Debug)] -pub struct StdChild(pub Child); - -impl StdChildWrapper for StdChild { +impl StdChildWrapper for Child { fn inner(&self) -> &dyn StdChildWrapper { self } @@ -227,22 +220,22 @@ impl StdChildWrapper for StdChild { self } fn stdin(&mut self) -> &mut Option { - &mut self.0.stdin + &mut self.stdin } fn stdout(&mut self) -> &mut Option { - &mut self.0.stdout + &mut self.stdout } fn stderr(&mut self) -> &mut Option { - &mut self.0.stderr + &mut self.stderr } fn id(&self) -> u32 { - self.0.id() + self.id() } fn try_wait(&mut self) -> Result> { - self.0.try_wait() + self.try_wait() } fn wait(&mut self) -> Result { - self.0.wait() + self.wait() } #[cfg(unix)] fn signal(&self, sig: i32) -> Result<()> { @@ -260,7 +253,7 @@ impl dyn StdChildWrapper { } fn is_raw_child(&self) -> bool { - self.downcast_ref::().is_some() + self.downcast_ref::().is_some() } /// Obtain a reference to the underlying [`Child`]. @@ -271,7 +264,7 @@ impl dyn StdChildWrapper { } // UNWRAP: we've just checked that it's Some with is_raw_child() - &inner.downcast_ref::().unwrap().0 + inner.downcast_ref().unwrap() } /// Obtain a mutable reference to the underlying [`Child`]. @@ -284,10 +277,7 @@ impl dyn StdChildWrapper { } // UNWRAP: we've just checked that with is_raw_child() - &mut (inner as &mut dyn Any) - .downcast_mut::() - .unwrap() - .0 + (inner as &mut dyn Any).downcast_mut().unwrap() } /// Obtain the underlying [`Child`]. @@ -300,7 +290,7 @@ impl dyn StdChildWrapper { } // UNWRAP: we've just checked that with is_raw_child() - (inner as Box).downcast::().unwrap().0 + *(inner as Box).downcast().unwrap() } } From 651cc09d324490af78b80b516835e318b55d08a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Sat, 28 Jun 2025 21:31:19 +1200 Subject: [PATCH 13/21] extra parens? --- tests/std_windows/kill_and_try_wait.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/std_windows/kill_and_try_wait.rs b/tests/std_windows/kill_and_try_wait.rs index 805bede..a8b8c67 100644 --- a/tests/std_windows/kill_and_try_wait.rs +++ b/tests/std_windows/kill_and_try_wait.rs @@ -8,7 +8,7 @@ fn nowrap() -> Result<()> { .spawn()?; assert!(child.try_wait()?.is_none(), "pre kill"); - (child.kill())?; + child.kill()?; sleep(DIE_TIME); assert!(child.try_wait()?.is_some(), "try_wait() one"); @@ -27,7 +27,7 @@ fn job_object() -> Result<()> { .spawn()?; assert!(child.try_wait()?.is_none(), "pre kill"); - (child.kill())?; + child.kill()?; sleep(DIE_TIME); assert!(child.try_wait()?.is_some(), "try_wait() one"); From 74929bdea55c9e7afbbc2de18e18e82ed4462127 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Sat, 28 Jun 2025 22:04:30 +1200 Subject: [PATCH 14/21] fix loop --- src/std/core.rs | 6 +++--- src/tokio/core.rs | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/std/core.rs b/src/std/core.rs index 3de386a..7ee98f1 100644 --- a/src/std/core.rs +++ b/src/std/core.rs @@ -229,13 +229,13 @@ impl StdChildWrapper for Child { &mut self.stderr } fn id(&self) -> u32 { - self.id() + Child::id(self) } fn try_wait(&mut self) -> Result> { - self.try_wait() + Child::try_wait(self) } fn wait(&mut self) -> Result { - self.wait() + Child::wait(self) } #[cfg(unix)] fn signal(&self, sig: i32) -> Result<()> { diff --git a/src/tokio/core.rs b/src/tokio/core.rs index 9271a28..e3d232b 100644 --- a/src/tokio/core.rs +++ b/src/tokio/core.rs @@ -226,16 +226,16 @@ impl TokioChildWrapper for Child { &mut self.stderr } fn id(&self) -> Option { - self.id() + Child::id(self) } fn start_kill(&mut self) -> Result<()> { - self.start_kill() + Child::start_kill(self) } fn try_wait(&mut self) -> Result> { - self.try_wait() + Child::try_wait(self) } fn wait(&mut self) -> Pin> + Send + '_>> { - Box::pin(self.wait()) + Box::pin(Child::wait(self)) } #[cfg(unix)] fn signal(&self, sig: i32) -> Result<()> { From 1fc90cbdf3af0d5aa3661570960244130c6a065c Mon Sep 17 00:00:00 2001 From: Brooks J Rady Date: Sat, 28 Jun 2025 23:23:21 +0100 Subject: [PATCH 15/21] fix(std): resolve stack overflow on Windows --- src/std/core.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/std/core.rs b/src/std/core.rs index 7ee98f1..86e0f59 100644 --- a/src/std/core.rs +++ b/src/std/core.rs @@ -127,15 +127,7 @@ pub trait StdChildWrapper: Any + std::fmt::Debug + Send { /// library uses it to provide a consistent API across both std and Tokio (and because it's a /// generally useful API). fn start_kill(&mut self) -> Result<()> { - #[cfg(unix)] - { - self.signal(Signal::SIGKILL as _) - } - - #[cfg(not(unix))] - { - self.inner_mut().kill() - } + self.inner_mut().start_kill() } /// Check if the `Child` has exited without blocking, and if so, return its exit status. @@ -231,6 +223,17 @@ impl StdChildWrapper for Child { fn id(&self) -> u32 { Child::id(self) } + fn start_kill(&mut self) -> Result<()> { + #[cfg(unix)] + { + self.signal(Signal::SIGKILL as _) + } + + #[cfg(not(unix))] + { + Child::kill(self) + } + } fn try_wait(&mut self) -> Result> { Child::try_wait(self) } From a19519ecd506c3c856f136df3669ad12e28382b5 Mon Sep 17 00:00:00 2001 From: Brooks J Rady Date: Sun, 29 Jun 2025 14:20:56 +0100 Subject: [PATCH 16/21] feat(api): add `&mut Command` to `pre_spawn()` This addition makes it possible to mutate the `Command` in `pre_spawn()`, spawn a `Child` from that mutated command, then roll-back the changes to command in `post_spawn()`. --- src/generic_wrap.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/generic_wrap.rs b/src/generic_wrap.rs index ce9c393..a2fe52a 100644 --- a/src/generic_wrap.rs +++ b/src/generic_wrap.rs @@ -91,7 +91,7 @@ macro_rules! Wrap { for (id, wrapper) in wrappers.iter_mut() { #[cfg(feature = "tracing")] ::tracing::debug!(?id, "post_spawn"); - wrapper.post_spawn(&mut child, self)?; + wrapper.post_spawn(command, &mut child, self)?; } let mut child = Box::new( @@ -204,7 +204,7 @@ macro_rules! Wrap { /// how `CreationFlags` on Windows works along with `JobObject`. /// /// Default: no-op. - fn post_spawn(&mut self, _child: &mut $child, _core: &$name) -> Result<()> { + fn post_spawn(&mut self, _command: &mut $command, _child: &mut $child, _core: &$name) -> Result<()> { Ok(()) } From ed76262ba043d12b5f14845d5d49fa47961da241 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Saparelli?= Date: Mon, 30 Jun 2025 12:00:54 +1200 Subject: [PATCH 17/21] fix stack overflow on windows thanks to @thelostlambda --- src/std/core.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/std/core.rs b/src/std/core.rs index 7ee98f1..86e0f59 100644 --- a/src/std/core.rs +++ b/src/std/core.rs @@ -127,15 +127,7 @@ pub trait StdChildWrapper: Any + std::fmt::Debug + Send { /// library uses it to provide a consistent API across both std and Tokio (and because it's a /// generally useful API). fn start_kill(&mut self) -> Result<()> { - #[cfg(unix)] - { - self.signal(Signal::SIGKILL as _) - } - - #[cfg(not(unix))] - { - self.inner_mut().kill() - } + self.inner_mut().start_kill() } /// Check if the `Child` has exited without blocking, and if so, return its exit status. @@ -231,6 +223,17 @@ impl StdChildWrapper for Child { fn id(&self) -> u32 { Child::id(self) } + fn start_kill(&mut self) -> Result<()> { + #[cfg(unix)] + { + self.signal(Signal::SIGKILL as _) + } + + #[cfg(not(unix))] + { + Child::kill(self) + } + } fn try_wait(&mut self) -> Result> { Child::try_wait(self) } From e64288bce91043c5452e1821be9873bbff02eed0 Mon Sep 17 00:00:00 2001 From: Brooks J Rady Date: Tue, 22 Jul 2025 14:52:23 +0100 Subject: [PATCH 18/21] docs: add doctests for an example logging wrapper --- Cargo.lock | 40 +++++++- Cargo.toml | 1 + src/lib.rs | 284 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 323 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e967f86..5786a67 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" @@ -176,6 +176,12 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" +[[package]] +name = "fastrand" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" + [[package]] name = "flate2" version = "1.1.1" @@ -360,6 +366,12 @@ dependencies = [ "libc", ] +[[package]] +name = "linux-raw-sys" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12" + [[package]] name = "log" version = "0.4.27" @@ -540,6 +552,7 @@ dependencies = [ "indexmap", "nix 0.30.1", "remoteprocess", + "tempfile", "tokio", "tracing", "windows", @@ -631,6 +644,19 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "rustix" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c71e83d6afe7ff64890ec6b71d6a69bb8a610ab78ce364b3352876bb4c801266" +dependencies = [ + "bitflags 2.9.1", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.59.0", +] + [[package]] name = "ruzstd" version = "0.7.3" @@ -713,6 +739,18 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "tempfile" +version = "3.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8a64e3985349f2441a1a9ef0b853f869006c3855f2cda6862a94d26ebb9d6a1" +dependencies = [ + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + [[package]] name = "tokio" version = "1.45.0" diff --git a/Cargo.toml b/Cargo.toml index 920483d..83a3f02 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,6 +36,7 @@ windows = { version = "0.61.1", optional = true } [dev-dependencies] remoteprocess = "0.5.0" +tempfile = { version = "3.20.0", default-features = false } tokio = { version = "1.38.2", features = ["io-util", "macros", "process", "rt", "rt-multi-thread", "time"] } [features] diff --git a/src/lib.rs b/src/lib.rs index 666c45e..eddc115 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,7 +9,6 @@ //! //! ```rust,no_run //! # fn main() -> std::io::Result<()> { -//! use std::process::Command; //! use process_wrap::std::*; //! //! let mut command = StdCommandWrap::with_new("watch", |command| { command.arg("ls"); }); @@ -150,6 +149,289 @@ //! If your functionality is order-dependent, make sure to specify so in your documentation! By //! default does nothing: no wrapping is performed and the input `child` is returned as-is. //! +//! ## An Example Logging Wrapper +//! +//! Let's implement a logging wrapper that redirects a `Command`'s `stdout` and `stderr` into a +//! text file. We can use `std::io::pipe` to merge `stdout` and `stderr` into one channel, then +//! `std::io::copy` in a background thread to non-blockingly stream that data to disk as it comes +//! in. +//! +//! ```rust +//! # use process_wrap::std::{StdCommandWrap, StdCommandWrapper}; +//! # use std::{fs::File, io, path::PathBuf, process::Command, thread}; +//! #[derive(Debug)] +//! struct LogFile { +//! path: PathBuf, +//! } +//! +//! impl LogFile { +//! fn new(path: impl Into) -> Self { +//! Self { path: path.into() } +//! } +//! } +//! +//! impl StdCommandWrapper for LogFile { +//! fn pre_spawn(&mut self, command: &mut Command, _core: &StdCommandWrap) -> io::Result<()> { +//! let mut logfile = File::create(&self.path)?; +//! let (mut rx, tx) = io::pipe()?; +//! +//! thread::spawn(move || { +//! io::copy(&mut rx, &mut logfile).unwrap(); +//! }); +//! +//! command.stdout(tx.try_clone()?).stderr(tx); +//! Ok(()) +//! } +//! } +//! ``` +//! +//! That's a great start, but it's actually introduced a resource leak: if the main thread of your +//! program exits before that background one does, then the background thread won't get a chance to +//! call `logfile`'s `Drop` implementation which closes the file. The file handle will be left open! +//! To fix this, we'll need to keep track of the background thread's `ThreadHandle` and `.join()` it +//! when calling `.wait()` on the `ChildWrapper`. +//! +//! ```rust +//! # use process_wrap::std::{StdChildWrapper, StdCommandWrap, StdCommandWrapper}; +//! # use std::{ +//! # fs::File, +//! # io, mem, +//! # path::PathBuf, +//! # process::{Command, ExitStatus}, +//! # thread::{self, JoinHandle}, +//! # }; +//! #[derive(Debug)] +//! struct LogFile { +//! path: PathBuf, +//! thread: Option>, +//! } +//! +//! impl LogFile { +//! fn new(path: impl Into) -> Self { +//! Self { +//! path: path.into(), +//! thread: None, +//! } +//! } +//! } +//! +//! impl StdCommandWrapper for LogFile { +//! fn pre_spawn(&mut self, command: &mut Command, _core: &StdCommandWrap) -> io::Result<()> { +//! let mut logfile = File::create(&self.path)?; +//! let (mut rx, tx) = io::pipe()?; +//! +//! self.thread = Some(thread::spawn(move || { +//! io::copy(&mut rx, &mut logfile).unwrap(); +//! })); +//! +//! command.stdout(tx.try_clone()?).stderr(tx); +//! Ok(()) +//! } +//! +//! fn wrap_child( +//! &mut self, +//! child: Box, +//! _core: &StdCommandWrap, +//! ) -> io::Result> { +//! let wrapped_child = LogFileChild { +//! inner: child, +//! thread: mem::take(&mut self.thread), +//! }; +//! Ok(Box::new(wrapped_child)) +//! } +//! } +//! +//! #[derive(Debug)] +//! struct LogFileChild { +//! inner: Box, +//! thread: Option>, +//! } +//! +//! impl StdChildWrapper for LogFileChild { +//! fn inner(&self) -> &dyn StdChildWrapper { +//! &*self.inner +//! } +//! +//! fn inner_mut(&mut self) -> &mut dyn StdChildWrapper { +//! &mut *self.inner +//! } +//! +//! fn into_inner(self: Box) -> Box { +//! self.inner +//! } +//! +//! fn wait(&mut self) -> io::Result { +//! let exit_status = self.inner.wait(); +//! +//! if let Some(thread) = mem::take(&mut self.thread) { +//! thread.join().unwrap(); +//! } +//! +//! exit_status +//! } +//! } +//! ``` +//! +//! Now we're cleaning up after ourselves, but there is one last issue: if you actually call +//! `.wait()`, then your program will deadlock! This is because `io::copy` copies data until `rx` +//! returns an EOF, but that only happens after *all* copies of `tx` are dropped. Currently, our +//! `Command` is holding onto `tx` even after calling `.spawn()`, so unless we manually drop the +//! `Command` (freeing both copies of `tx`) before calling `.wait()`, our program will deadlock! +//! We can fix this by telling `Command` to drop `tx` right after spawning the child — by this +//! point, the `ChildWrapper` will have already inherited the copies of `tx` that it needs, so +//! dropping `tx` from `Command` should be totally safe. We'll get `Command` to "drop" `tx` by +//! setting its `stdin` and `stdout` to `Stdio::null()` in `CommandWrapper::post_spawn()`. +//! +//! ```rust +//! # use process_wrap::std::{StdCommandWrap, StdCommandWrapper}; +//! # use std::{ +//! # io, +//! # path::PathBuf, +//! # process::{Child, Command, Stdio}, +//! # thread::JoinHandle, +//! # }; +//! # #[derive(Debug)] +//! # struct LogFile { +//! # path: PathBuf, +//! # thread: Option>, +//! # } +//! # +//! impl StdCommandWrapper for LogFile { +//! // ... snip ... +//! fn post_spawn( +//! &mut self, +//! command: &mut Command, +//! _child: &mut Child, +//! _core: &StdCommandWrap, +//! ) -> io::Result<()> { +//! command.stdout(Stdio::null()).stderr(Stdio::null()); +//! +//! Ok(()) +//! } +//! // ... snip ... +//! } +//! ``` +//! +//! Finally, we can test that our new command-wrapper works: +//! +//! ```rust +//! # use process_wrap::std::{StdChildWrapper, StdCommandWrap, StdCommandWrapper}; +//! # use std::{ +//! # error::Error, +//! # fs::{self, File}, +//! # io, mem, +//! # path::PathBuf, +//! # process::{Child, Command, ExitStatus, Stdio}, +//! # thread::{self, JoinHandle}, +//! # }; +//! # use tempfile::NamedTempFile; +//! # #[derive(Debug)] +//! # struct LogFile { +//! # path: PathBuf, +//! # thread: Option>, +//! # } +//! # +//! # impl LogFile { +//! # fn new(path: impl Into) -> Self { +//! # Self { +//! # path: path.into(), +//! # thread: None, +//! # } +//! # } +//! # } +//! # +//! # impl StdCommandWrapper for LogFile { +//! # fn pre_spawn(&mut self, command: &mut Command, _core: &StdCommandWrap) -> io::Result<()> { +//! # let mut logfile = File::create(&self.path)?; +//! # let (mut rx, tx) = io::pipe()?; +//! # +//! # self.thread = Some(thread::spawn(move || { +//! # io::copy(&mut rx, &mut logfile).unwrap(); +//! # })); +//! # +//! # command.stdout(tx.try_clone()?).stderr(tx); +//! # Ok(()) +//! # } +//! # +//! # fn post_spawn( +//! # &mut self, +//! # command: &mut Command, +//! # _child: &mut Child, +//! # _core: &StdCommandWrap, +//! # ) -> io::Result<()> { +//! # command.stdout(Stdio::null()).stderr(Stdio::null()); +//! # +//! # Ok(()) +//! # } +//! # +//! # fn wrap_child( +//! # &mut self, +//! # child: Box, +//! # _core: &StdCommandWrap, +//! # ) -> io::Result> { +//! # let wrapped_child = LogFileChild { +//! # inner: child, +//! # thread: mem::take(&mut self.thread), +//! # }; +//! # Ok(Box::new(wrapped_child)) +//! # } +//! # } +//! # +//! # #[derive(Debug)] +//! # struct LogFileChild { +//! # inner: Box, +//! # thread: Option>, +//! # } +//! # +//! # impl StdChildWrapper for LogFileChild { +//! # fn inner(&self) -> &dyn StdChildWrapper { +//! # &*self.inner +//! # } +//! # +//! # fn inner_mut(&mut self) -> &mut dyn StdChildWrapper { +//! # &mut *self.inner +//! # } +//! # +//! # fn into_inner(self: Box) -> Box { +//! # self.inner +//! # } +//! # +//! # fn wait(&mut self) -> io::Result { +//! # let exit_status = self.inner.wait(); +//! # +//! # if let Some(thread) = mem::take(&mut self.thread) { +//! # thread.join().unwrap(); +//! # } +//! # +//! # exit_status +//! # } +//! # } +//! # +//! fn main() -> Result<(), Box> { +//! #[cfg(windows)] +//! let mut command = StdCommandWrap::with_new("cmd", |command| { +//! command.args(["/c", "echo Hello && echo World 1>&2"]); +//! }); +//! #[cfg(unix)] +//! let mut command = StdCommandWrap::with_new("sh", |command| { +//! command.args(["-c", "echo Hello && echo World 1>&2"]); +//! }); +//! +//! let logfile = NamedTempFile::new()?; +//! let logfile_path = logfile.path(); +//! +//! command.wrap(LogFile::new(logfile_path)).spawn()?.wait()?; +//! +//! let logfile_lines: Vec = fs::read_to_string(logfile_path)? +//! .lines() +//! .map(|l| l.trim().into()) +//! .collect(); +//! assert_eq!(logfile_lines, vec!["Hello", "World"]); +//! +//! Ok(()) +//! } +//! ``` +//! //! # Features //! //! ## Frontends From 225005ec6fe40cd9799f4c6c8a98ecc4d493545c Mon Sep 17 00:00:00 2001 From: Brooks J Rady Date: Tue, 22 Jul 2025 17:42:41 +0100 Subject: [PATCH 19/21] refactor: remove `Std` and `Tokio` type prefixes --- src/generic_wrap.rs | 32 +++---- src/lib.rs | 90 +++++++++---------- src/std.rs | 2 +- src/std/core.rs | 37 ++++---- src/std/creation_flags.rs | 2 +- src/std/job_object.rs | 2 +- src/std/process_group.rs | 24 ++--- src/std/process_session.rs | 12 +-- src/std/reset_sigmask.rs | 6 +- src/tokio.rs | 2 +- src/tokio/core.rs | 37 ++++---- src/tokio/creation_flags.rs | 2 +- src/tokio/job_object.rs | 2 +- src/tokio/kill_on_drop.rs | 6 +- src/tokio/process_group.rs | 24 ++--- src/tokio/process_session.rs | 12 +-- src/tokio/reset_sigmask.rs | 6 +- tests/std_unix/id_same_as_inner.rs | 6 +- tests/std_unix/inner_read_stdout.rs | 6 +- tests/std_unix/into_inner_write_stdin.rs | 6 +- tests/std_unix/kill_and_try_wait.rs | 6 +- tests/std_unix/multiproc_linux.rs | 8 +- tests/std_unix/signals.rs | 6 +- tests/std_unix/try_wait_after_die.rs | 6 +- .../std_unix/try_wait_twice_after_sigterm.rs | 6 +- tests/std_unix/wait_after_die.rs | 6 +- tests/std_unix/wait_twice.rs | 6 +- tests/std_unix/wait_twice_after_sigterm.rs | 6 +- tests/std_unix/wait_with_output.rs | 6 +- tests/std_windows/id_same_as_inner.rs | 4 +- tests/std_windows/inner_read_stdout.rs | 4 +- tests/std_windows/into_inner_write_stdin.rs | 4 +- tests/std_windows/kill_and_try_wait.rs | 4 +- tests/std_windows/try_wait_after_die.rs | 4 +- tests/std_windows/wait_after_die.rs | 4 +- tests/std_windows/wait_twice.rs | 4 +- tests/std_windows/wait_with_output.rs | 4 +- tests/tokio_unix/id_same_as_inner.rs | 6 +- tests/tokio_unix/inner_read_stdout.rs | 6 +- tests/tokio_unix/into_inner_write_stdin.rs | 6 +- tests/tokio_unix/kill_and_try_wait.rs | 6 +- tests/tokio_unix/multiproc_linux.rs | 8 +- tests/tokio_unix/signals.rs | 6 +- tests/tokio_unix/try_wait_after_die.rs | 6 +- .../try_wait_twice_after_sigterm.rs | 6 +- tests/tokio_unix/wait_after_die.rs | 6 +- tests/tokio_unix/wait_twice.rs | 6 +- tests/tokio_unix/wait_twice_after_sigterm.rs | 6 +- tests/tokio_unix/wait_with_output.rs | 6 +- tests/tokio_windows/id_same_as_inner.rs | 4 +- tests/tokio_windows/inner_read_stdout.rs | 4 +- tests/tokio_windows/into_inner_write_stdin.rs | 4 +- tests/tokio_windows/kill_and_try_wait.rs | 4 +- tests/tokio_windows/try_wait_after_die.rs | 4 +- tests/tokio_windows/wait_after_die.rs | 4 +- tests/tokio_windows/wait_twice.rs | 4 +- tests/tokio_windows/wait_with_output.rs | 4 +- 57 files changed, 248 insertions(+), 262 deletions(-) diff --git a/src/generic_wrap.rs b/src/generic_wrap.rs index a2fe52a..d6e5ed4 100644 --- a/src/generic_wrap.rs +++ b/src/generic_wrap.rs @@ -4,24 +4,24 @@ )] macro_rules! Wrap { - ($name:ident, $command:ty, $wrapper:ident, $child:ty, $childer:ident, $first_child_wrapper:expr) => { + ($command:ty, $child:ty, $childer:ident, $first_child_wrapper:expr) => { /// A wrapper around a `Command` that allows for additional functionality to be added. /// /// This is the core type of the `process-wrap` crate. It is a wrapper around a #[doc = concat!("[`", stringify!($command), "`].")] #[derive(Debug)] - pub struct $name { + pub struct CommandWrap { command: $command, - wrappers: ::indexmap::IndexMap<::std::any::TypeId, Box>, + wrappers: ::indexmap::IndexMap<::std::any::TypeId, Box>, } - impl $name { + impl CommandWrap { /// Create from a program name and a closure to configure the command. /// /// This is a convenience method that creates a new `Command` and then calls the closure /// to configure it. The `Command` is then wrapped and returned. /// - #[doc = concat!("Alternatively, use `From`/`Into` to convert a [`", stringify!($command),"`] to a [`", stringify!($name), "`].")] + #[doc = concat!("Alternatively, use `From`/`Into` to convert a [`", stringify!($command),"`] to a [`", stringify!(CommandWrap), "`].")] pub fn with_new( program: impl AsRef<::std::ffi::OsStr>, init: impl FnOnce(&mut $command), @@ -60,7 +60,7 @@ macro_rules! Wrap { /// will be silently discarded. /// /// Returns `&mut self` for chaining. - pub fn wrap(&mut self, wrapper: W) -> &mut Self { + pub fn wrap(&mut self, wrapper: W) -> &mut Self { let typeid = ::std::any::TypeId::of::(); let mut wrapper = Some(Box::new(wrapper)); let extant = self @@ -79,7 +79,7 @@ macro_rules! Wrap { fn spawn_inner( &self, command: &mut $command, - wrappers: &mut ::indexmap::IndexMap<::std::any::TypeId, Box>, + wrappers: &mut ::indexmap::IndexMap<::std::any::TypeId, Box>, ) -> ::std::io::Result> { for (id, wrapper) in wrappers.iter_mut() { #[cfg(feature = "tracing")] @@ -127,7 +127,7 @@ macro_rules! Wrap { } /// Check if a wrapper of a given type is present. - pub fn has_wrap(&self) -> bool { + pub fn has_wrap(&self) -> bool { let typeid = ::std::any::TypeId::of::(); self.wrappers.contains_key(&typeid) } @@ -139,7 +139,7 @@ macro_rules! Wrap { /// /// Returns `None` if the wrapper is not present. To merely check if a wrapper is /// present, use `has_wrap` instead. - pub fn get_wrap(&self) -> Option<&W> { + pub fn get_wrap(&self) -> Option<&W> { let typeid = ::std::any::TypeId::of::(); self.wrappers.get(&typeid).map(|w| { let w_any = w as &dyn ::std::any::Any; @@ -150,7 +150,7 @@ macro_rules! Wrap { } } - impl From for $name { + impl From for CommandWrap { fn from(command: $command) -> Self { Self { command, @@ -169,8 +169,8 @@ macro_rules! Wrap { /// ```rust,ignore /// #[derive(Debug)] /// pub struct YourWrapper; - #[doc = concat!("impl ", stringify!($wrapper), " for YourWrapper {}\n```")] - pub trait $wrapper: ::std::fmt::Debug + Send + Sync { + #[doc = concat!("impl ", stringify!(CommandWrapper), " for YourWrapper {}\n```")] + pub trait CommandWrapper: ::std::fmt::Debug + Send + Sync { /// Called on a first instance if a second of the same type is added. /// /// Only one of a wrapper type can exist within a Wrap at a time. The default behaviour @@ -184,7 +184,7 @@ macro_rules! Wrap { /// downcasting fails, instead of using unchecked downcasting and unleashing UB. /// /// Default impl: no-op. - fn extend(&mut self, _other: Box) {} + fn extend(&mut self, _other: Box) {} /// Called before the command is spawned, to mutate it as needed. /// @@ -194,7 +194,7 @@ macro_rules! Wrap { /// `CreationFlags` on Windows works along with `JobObject`. /// /// Defaut impl: no-op. - fn pre_spawn(&mut self, _command: &mut $command, _core: &$name) -> Result<()> { + fn pre_spawn(&mut self, _command: &mut $command, _core: &CommandWrap) -> Result<()> { Ok(()) } @@ -204,7 +204,7 @@ macro_rules! Wrap { /// how `CreationFlags` on Windows works along with `JobObject`. /// /// Default: no-op. - fn post_spawn(&mut self, _command: &mut $command, _child: &mut $child, _core: &$name) -> Result<()> { + fn post_spawn(&mut self, _command: &mut $command, _child: &mut $child, _core: &CommandWrap) -> Result<()> { Ok(()) } @@ -222,7 +222,7 @@ macro_rules! Wrap { fn wrap_child( &mut self, child: Box, - _core: &$name, + _core: &CommandWrap, ) -> Result> { Ok(child) } diff --git a/src/lib.rs b/src/lib.rs index eddc115..79d81b6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,7 +11,7 @@ //! # fn main() -> std::io::Result<()> { //! use process_wrap::std::*; //! -//! let mut command = StdCommandWrap::with_new("watch", |command| { command.arg("ls"); }); +//! let mut command = CommandWrap::with_new("watch", |command| { command.arg("ls"); }); //! #[cfg(unix)] { command.wrap(ProcessGroup::leader()); } //! #[cfg(windows)] { command.wrap(JobObject); } //! let mut child = command.spawn()?; @@ -36,7 +36,7 @@ //! //! # Usage //! -//! The core API is [`StdCommandWrap`](std::StdCommandWrap) and [`TokioCommandWrap`](tokio::TokioCommandWrap), +//! The core API is [`CommandWrap`](std::CommandWrap) and [`CommandWrap`](tokio::CommandWrap), //! which can be constructed either directly from an existing `process::Command`: //! //! ```rust @@ -44,7 +44,7 @@ //! use std::process::Command; //! let mut command = Command::new("ls"); //! command.arg("-l"); -//! let mut command = StdCommandWrap::from(command); +//! let mut command = CommandWrap::from(command); //! #[cfg(unix)] { command.wrap(ProcessGroup::leader()); } //! #[cfg(windows)] { command.wrap(JobObject); } //! ``` @@ -53,7 +53,7 @@ //! //! ```rust //! use process_wrap::std::*; -//! let mut command = StdCommandWrap::with_new("ls", |command| { command.arg("-l"); }); +//! let mut command = CommandWrap::with_new("ls", |command| { command.arg("-l"); }); //! #[cfg(unix)] { command.wrap(ProcessGroup::leader()); } //! #[cfg(windows)] { command.wrap(JobObject); } //! ``` @@ -62,7 +62,7 @@ //! //! ```rust //! use process_wrap::std::*; -//! StdCommandWrap::with_new("ls", |command| { command.arg("-l"); }) +//! CommandWrap::with_new("ls", |command| { command.arg("-l"); }) //! .wrap(ProcessGroup::leader()); //! ``` //! @@ -89,7 +89,7 @@ //! //! ```rust //! use process_wrap::tokio::*; -//! let mut command = TokioCommandWrap::with_new("ls", |command| { command.arg("-l"); }); +//! let mut command = CommandWrap::with_new("ls", |command| { command.arg("-l"); }); //! command.wrap(KillOnDrop); //! ``` //! @@ -97,7 +97,7 @@ //! //! ```rust,ignore //! use process_wrap::std::*; -//! let mut command = StdCommandWrap::with_new("ls", |command| { command.arg("-l"); }); +//! let mut command = CommandWrap::with_new("ls", |command| { command.arg("-l"); }); //! command.wrap(CreationFlags(CREATE_NO_WINDOW)); //! ``` //! @@ -112,8 +112,8 @@ //! underlying APIs. Of course you can (and should) re-use/share code wherever possible if //! implementing both. //! -//! At minimum, you must implement [`StdCommandWrapper`](crate::std::StdCommandWrapper) and/or -//! [`TokioCommandWrapper`](crate::tokio::TokioCommandWrapper). These provide the same functionality +//! At minimum, you must implement [`CommandWrapper`](crate::std::CommandWrapper) and/or +//! [`CommandWrapper`](crate::tokio::CommandWrapper). These provide the same functionality //! (and indeed internally are generated using a common macro), but differ in the exact types used. //! Here's the most basic impl (shown for Tokio): //! @@ -121,27 +121,27 @@ //! use process_wrap::tokio::*; //! #[derive(Debug)] //! pub struct YourWrapper; -//! impl TokioCommandWrapper for YourWrapper {} +//! impl CommandWrapper for YourWrapper {} //! ``` //! //! The trait provides extension or hook points into the lifecycle of a `Command`: //! -//! - **`fn extend(&mut self, other: Box)`** is called if +//! - **`fn extend(&mut self, other: Box)`** is called if //! `.wrap(YourWrapper)` is done twice. Only one of a wrapper type can exist, so this gives the //! opportunity to incorporate all or part of the second wrapper instance into the first. By //! default, this does nothing (ie only the first registered wrapper instance of a type applies). //! -//! - **`fn pre_spawn(&mut self, command: &mut Command, core: &TokioCommandWrap)`** is called before +//! - **`fn pre_spawn(&mut self, command: &mut Command, core: &CommandWrap)`** is called before //! the command is spawned, and gives mutable access to it. It also gives mutable access to the //! wrapper instance, so state can be stored if needed. The `core` reference gives access to data //! from other wrappers; for example, that's how `CreationFlags` on Windows works along with //! `JobObject`. By default does nothing. //! -//! - **`fn post_spawn(&mut self, child: &mut tokio::process::Child, core: &TokioCommandWrap)`** is +//! - **`fn post_spawn(&mut self, child: &mut tokio::process::Child, core: &CommandWrap)`** is //! called after spawn, and should be used for any necessary cleanups. It is offered for //! completeness but is expected to be less used than `wrap_child()`. By default does nothing. //! -//! - **`fn wrap_child(&mut self, child: Box, core: &TokioCommandWrap)`** is +//! - **`fn wrap_child(&mut self, child: Box, core: &CommandWrap)`** is //! called after all `post_spawn()`s have run. If your wrapper needs to override the methods on //! Child, then it should create an instance of its own type implementing `TokioChildWrapper` and //! return it here. Child wraps are _in order_: you may end up with a `Foo(Bar(Child))` or a @@ -157,7 +157,7 @@ //! in. //! //! ```rust -//! # use process_wrap::std::{StdCommandWrap, StdCommandWrapper}; +//! # use process_wrap::std::{CommandWrap, CommandWrapper}; //! # use std::{fs::File, io, path::PathBuf, process::Command, thread}; //! #[derive(Debug)] //! struct LogFile { @@ -170,8 +170,8 @@ //! } //! } //! -//! impl StdCommandWrapper for LogFile { -//! fn pre_spawn(&mut self, command: &mut Command, _core: &StdCommandWrap) -> io::Result<()> { +//! impl CommandWrapper for LogFile { +//! fn pre_spawn(&mut self, command: &mut Command, _core: &CommandWrap) -> io::Result<()> { //! let mut logfile = File::create(&self.path)?; //! let (mut rx, tx) = io::pipe()?; //! @@ -192,7 +192,7 @@ //! when calling `.wait()` on the `ChildWrapper`. //! //! ```rust -//! # use process_wrap::std::{StdChildWrapper, StdCommandWrap, StdCommandWrapper}; +//! # use process_wrap::std::{ChildWrapper, CommandWrap, CommandWrapper}; //! # use std::{ //! # fs::File, //! # io, mem, @@ -215,8 +215,8 @@ //! } //! } //! -//! impl StdCommandWrapper for LogFile { -//! fn pre_spawn(&mut self, command: &mut Command, _core: &StdCommandWrap) -> io::Result<()> { +//! impl CommandWrapper for LogFile { +//! fn pre_spawn(&mut self, command: &mut Command, _core: &CommandWrap) -> io::Result<()> { //! let mut logfile = File::create(&self.path)?; //! let (mut rx, tx) = io::pipe()?; //! @@ -230,9 +230,9 @@ //! //! fn wrap_child( //! &mut self, -//! child: Box, -//! _core: &StdCommandWrap, -//! ) -> io::Result> { +//! child: Box, +//! _core: &CommandWrap, +//! ) -> io::Result> { //! let wrapped_child = LogFileChild { //! inner: child, //! thread: mem::take(&mut self.thread), @@ -243,20 +243,20 @@ //! //! #[derive(Debug)] //! struct LogFileChild { -//! inner: Box, +//! inner: Box, //! thread: Option>, //! } //! -//! impl StdChildWrapper for LogFileChild { -//! fn inner(&self) -> &dyn StdChildWrapper { +//! impl ChildWrapper for LogFileChild { +//! fn inner(&self) -> &dyn ChildWrapper { //! &*self.inner //! } //! -//! fn inner_mut(&mut self) -> &mut dyn StdChildWrapper { +//! fn inner_mut(&mut self) -> &mut dyn ChildWrapper { //! &mut *self.inner //! } //! -//! fn into_inner(self: Box) -> Box { +//! fn into_inner(self: Box) -> Box { //! self.inner //! } //! @@ -283,7 +283,7 @@ //! setting its `stdin` and `stdout` to `Stdio::null()` in `CommandWrapper::post_spawn()`. //! //! ```rust -//! # use process_wrap::std::{StdCommandWrap, StdCommandWrapper}; +//! # use process_wrap::std::{CommandWrap, CommandWrapper}; //! # use std::{ //! # io, //! # path::PathBuf, @@ -296,13 +296,13 @@ //! # thread: Option>, //! # } //! # -//! impl StdCommandWrapper for LogFile { +//! impl CommandWrapper for LogFile { //! // ... snip ... //! fn post_spawn( //! &mut self, //! command: &mut Command, //! _child: &mut Child, -//! _core: &StdCommandWrap, +//! _core: &CommandWrap, //! ) -> io::Result<()> { //! command.stdout(Stdio::null()).stderr(Stdio::null()); //! @@ -315,7 +315,7 @@ //! Finally, we can test that our new command-wrapper works: //! //! ```rust -//! # use process_wrap::std::{StdChildWrapper, StdCommandWrap, StdCommandWrapper}; +//! # use process_wrap::std::{ChildWrapper, CommandWrap, CommandWrapper}; //! # use std::{ //! # error::Error, //! # fs::{self, File}, @@ -340,8 +340,8 @@ //! # } //! # } //! # -//! # impl StdCommandWrapper for LogFile { -//! # fn pre_spawn(&mut self, command: &mut Command, _core: &StdCommandWrap) -> io::Result<()> { +//! # impl CommandWrapper for LogFile { +//! # fn pre_spawn(&mut self, command: &mut Command, _core: &CommandWrap) -> io::Result<()> { //! # let mut logfile = File::create(&self.path)?; //! # let (mut rx, tx) = io::pipe()?; //! # @@ -357,7 +357,7 @@ //! # &mut self, //! # command: &mut Command, //! # _child: &mut Child, -//! # _core: &StdCommandWrap, +//! # _core: &CommandWrap, //! # ) -> io::Result<()> { //! # command.stdout(Stdio::null()).stderr(Stdio::null()); //! # @@ -366,9 +366,9 @@ //! # //! # fn wrap_child( //! # &mut self, -//! # child: Box, -//! # _core: &StdCommandWrap, -//! # ) -> io::Result> { +//! # child: Box, +//! # _core: &CommandWrap, +//! # ) -> io::Result> { //! # let wrapped_child = LogFileChild { //! # inner: child, //! # thread: mem::take(&mut self.thread), @@ -379,20 +379,20 @@ //! # //! # #[derive(Debug)] //! # struct LogFileChild { -//! # inner: Box, +//! # inner: Box, //! # thread: Option>, //! # } //! # -//! # impl StdChildWrapper for LogFileChild { -//! # fn inner(&self) -> &dyn StdChildWrapper { +//! # impl ChildWrapper for LogFileChild { +//! # fn inner(&self) -> &dyn ChildWrapper { //! # &*self.inner //! # } //! # -//! # fn inner_mut(&mut self) -> &mut dyn StdChildWrapper { +//! # fn inner_mut(&mut self) -> &mut dyn ChildWrapper { //! # &mut *self.inner //! # } //! # -//! # fn into_inner(self: Box) -> Box { +//! # fn into_inner(self: Box) -> Box { //! # self.inner //! # } //! # @@ -409,11 +409,11 @@ //! # //! fn main() -> Result<(), Box> { //! #[cfg(windows)] -//! let mut command = StdCommandWrap::with_new("cmd", |command| { +//! let mut command = CommandWrap::with_new("cmd", |command| { //! command.args(["/c", "echo Hello && echo World 1>&2"]); //! }); //! #[cfg(unix)] -//! let mut command = StdCommandWrap::with_new("sh", |command| { +//! let mut command = CommandWrap::with_new("sh", |command| { //! command.args(["-c", "echo Hello && echo World 1>&2"]); //! }); //! diff --git a/src/std.rs b/src/std.rs index f3e30fd..8f9451a 100644 --- a/src/std.rs +++ b/src/std.rs @@ -9,7 +9,7 @@ //! ``` #[doc(inline)] -pub use core::{StdChildWrapper, StdCommandWrap, StdCommandWrapper}; +pub use core::{ChildWrapper, CommandWrap, CommandWrapper}; #[cfg(all(windows, feature = "creation-flags"))] #[doc(inline)] pub use creation_flags::CreationFlags; diff --git a/src/std/core.rs b/src/std/core.rs index 86e0f59..6164aec 100644 --- a/src/std/core.rs +++ b/src/std/core.rs @@ -10,14 +10,7 @@ use nix::{ unistd::Pid, }; -crate::generic_wrap::Wrap!( - StdCommandWrap, - Command, - StdCommandWrapper, - Child, - StdChildWrapper, - |child| child -); +crate::generic_wrap::Wrap!(Command, Child, ChildWrapper, |child| child); /// Wrapper for `std::process::Child`. /// @@ -41,39 +34,39 @@ crate::generic_wrap::Wrap!( /// #[derive(Debug)] /// pub struct YourChildWrapper(Child); /// -/// impl StdChildWrapper for YourChildWrapper { -/// fn inner(&self) -> &dyn StdChildWrapper { +/// impl ChildWrapper for YourChildWrapper { +/// fn inner(&self) -> &dyn ChildWrapper { /// &self.0 /// } /// -/// fn inner_mut(&mut self) -> &mut dyn StdChildWrapper { +/// fn inner_mut(&mut self) -> &mut dyn ChildWrapper { /// &mut self.0 /// } /// -/// fn into_inner(self: Box) -> Box { +/// fn into_inner(self: Box) -> Box { /// Box::new((*self).0) /// } /// } /// ``` -pub trait StdChildWrapper: Any + std::fmt::Debug + Send { +pub trait ChildWrapper: Any + std::fmt::Debug + Send { /// Obtain a reference to the wrapped child. - fn inner(&self) -> &dyn StdChildWrapper; + fn inner(&self) -> &dyn ChildWrapper; /// Obtain a mutable reference to the wrapped child. - fn inner_mut(&mut self) -> &mut dyn StdChildWrapper; + fn inner_mut(&mut self) -> &mut dyn ChildWrapper; /// Consume the current wrapper and return the wrapped child. /// /// Note that this may disrupt whatever the current wrapper was doing. However, wrappers must /// ensure that the wrapped child is in a consistent state when this is called or they are /// dropped, so that this is always safe. - fn into_inner(self: Box) -> Box; + fn into_inner(self: Box) -> Box; /// Obtain a clone if possible. /// /// Some implementations may make it possible to clone the implementing structure, even though /// std's `Child` isn't `Clone`. In those cases, this method should be overridden. - fn try_clone(&self) -> Option> { + fn try_clone(&self) -> Option> { None } @@ -201,14 +194,14 @@ pub trait StdChildWrapper: Any + std::fmt::Debug + Send { } } -impl StdChildWrapper for Child { - fn inner(&self) -> &dyn StdChildWrapper { +impl ChildWrapper for Child { + fn inner(&self) -> &dyn ChildWrapper { self } - fn inner_mut(&mut self) -> &mut dyn StdChildWrapper { + fn inner_mut(&mut self) -> &mut dyn ChildWrapper { self } - fn into_inner(self: Box) -> Box { + fn into_inner(self: Box) -> Box { self } fn stdin(&mut self) -> &mut Option { @@ -250,7 +243,7 @@ impl StdChildWrapper for Child { } } -impl dyn StdChildWrapper { +impl dyn ChildWrapper { fn downcast_ref(&self) -> Option<&T> { (self as &dyn Any).downcast_ref() } diff --git a/src/std/creation_flags.rs b/src/std/creation_flags.rs index 1b0a85a..5be7f6b 100644 --- a/src/std/creation_flags.rs +++ b/src/std/creation_flags.rs @@ -2,7 +2,7 @@ use std::{io::Result, os::windows::process::CommandExt, process::Command}; use windows::Win32::System::Threading::PROCESS_CREATION_FLAGS; -use super::{StdCommandWrap, StdCommandWrapper}; +use super::{CommandWrap, CommandWrapper}; /// Shim wrapper which sets Windows process creation flags. /// diff --git a/src/std/job_object.rs b/src/std/job_object.rs index f557e97..a997ef3 100644 --- a/src/std/job_object.rs +++ b/src/std/job_object.rs @@ -19,7 +19,7 @@ use crate::{ #[cfg(feature = "creation-flags")] use super::CreationFlags; -use super::{StdChildWrapper, StdCommandWrap, StdCommandWrapper}; +use super::{StdChildWrapper, CommandWrap, CommandWrapper}; /// Wrapper which creates a job object context for a `Command`. /// diff --git a/src/std/process_group.rs b/src/std/process_group.rs index d34356d..59cf54c 100644 --- a/src/std/process_group.rs +++ b/src/std/process_group.rs @@ -19,7 +19,7 @@ use tracing::instrument; use crate::ChildExitStatus; -use super::{StdChildWrapper, StdCommandWrap, StdCommandWrapper}; +use super::{ChildWrapper, CommandWrap, CommandWrapper}; /// Wrapper which sets the process group of a `Command`. /// @@ -56,14 +56,14 @@ impl ProcessGroup { /// Wrapper for `Child` which ensures that all processes in the group are reaped. #[derive(Debug)] pub struct ProcessGroupChild { - inner: Box, + inner: Box, exit_status: ChildExitStatus, pgid: Pid, } impl ProcessGroupChild { #[cfg_attr(feature = "tracing", instrument(level = "debug"))] - pub(crate) fn new(inner: Box, pgid: Pid) -> Self { + pub(crate) fn new(inner: Box, pgid: Pid) -> Self { Self { inner, exit_status: ChildExitStatus::Running, @@ -79,9 +79,9 @@ impl ProcessGroupChild { } } -impl StdCommandWrapper for ProcessGroup { +impl CommandWrapper for ProcessGroup { #[cfg_attr(feature = "tracing", instrument(level = "debug", skip(self)))] - fn pre_spawn(&mut self, command: &mut Command, _core: &StdCommandWrap) -> Result<()> { + fn pre_spawn(&mut self, command: &mut Command, _core: &CommandWrap) -> Result<()> { command.process_group(self.leader.as_raw()); Ok(()) } @@ -89,9 +89,9 @@ impl StdCommandWrapper for ProcessGroup { #[cfg_attr(feature = "tracing", instrument(level = "debug", skip(self)))] fn wrap_child( &mut self, - inner: Box, - _core: &StdCommandWrap, - ) -> Result> { + inner: Box, + _core: &CommandWrap, + ) -> Result> { let pgid = Pid::from_raw(i32::try_from(inner.id()).expect("Command PID > i32::MAX")); Ok(Box::new(ProcessGroupChild::new(inner, pgid))) @@ -149,14 +149,14 @@ impl ProcessGroupChild { } } -impl StdChildWrapper for ProcessGroupChild { - fn inner(&self) -> &dyn StdChildWrapper { +impl ChildWrapper for ProcessGroupChild { + fn inner(&self) -> &dyn ChildWrapper { self.inner.inner() } - fn inner_mut(&mut self) -> &mut dyn StdChildWrapper { + fn inner_mut(&mut self) -> &mut dyn ChildWrapper { self.inner.inner_mut() } - fn into_inner(self: Box) -> Box { + fn into_inner(self: Box) -> Box { self.inner.into_inner() } diff --git a/src/std/process_session.rs b/src/std/process_session.rs index 42c9a0b..235f7f8 100644 --- a/src/std/process_session.rs +++ b/src/std/process_session.rs @@ -8,7 +8,7 @@ use nix::unistd::{setsid, Pid}; #[cfg(feature = "tracing")] use tracing::instrument; -use super::{StdCommandWrap, StdCommandWrapper}; +use super::{CommandWrap, CommandWrapper}; /// Wrapper which creates a new session and group for the `Command`. /// @@ -25,9 +25,9 @@ use super::{StdCommandWrap, StdCommandWrapper}; #[derive(Clone, Copy, Debug)] pub struct ProcessSession; -impl StdCommandWrapper for ProcessSession { +impl CommandWrapper for ProcessSession { #[cfg_attr(feature = "tracing", instrument(level = "debug", skip(self)))] - fn pre_spawn(&mut self, command: &mut Command, _core: &StdCommandWrap) -> Result<()> { + fn pre_spawn(&mut self, command: &mut Command, _core: &CommandWrap) -> Result<()> { unsafe { command.pre_exec(move || setsid().map_err(Error::from).map(|_| ())); } @@ -38,9 +38,9 @@ impl StdCommandWrapper for ProcessSession { #[cfg_attr(feature = "tracing", instrument(level = "debug", skip(self)))] fn wrap_child( &mut self, - inner: Box, - _core: &StdCommandWrap, - ) -> Result> { + inner: Box, + _core: &CommandWrap, + ) -> Result> { let pgid = Pid::from_raw(i32::try_from(inner.id()).expect("Command PID > i32::MAX")); Ok(Box::new(super::ProcessGroupChild::new(inner, pgid))) diff --git a/src/std/reset_sigmask.rs b/src/std/reset_sigmask.rs index adbdbf6..dc8e03b 100644 --- a/src/std/reset_sigmask.rs +++ b/src/std/reset_sigmask.rs @@ -4,7 +4,7 @@ use nix::sys::signal::{sigprocmask, SigSet, SigmaskHow}; #[cfg(feature = "tracing")] use tracing::trace; -use super::{StdCommandWrap, StdCommandWrapper}; +use super::{CommandWrap, CommandWrapper}; /// Wrapper which resets the process signal mask. /// @@ -13,8 +13,8 @@ use super::{StdCommandWrap, StdCommandWrapper}; #[derive(Clone, Copy, Debug)] pub struct ResetSigmask; -impl StdCommandWrapper for ResetSigmask { - fn pre_spawn(&mut self, command: &mut Command, _core: &StdCommandWrap) -> Result<()> { +impl CommandWrapper for ResetSigmask { + fn pre_spawn(&mut self, command: &mut Command, _core: &CommandWrap) -> Result<()> { unsafe { command.pre_exec(|| { let mut oldset = SigSet::empty(); diff --git a/src/tokio.rs b/src/tokio.rs index 28bee52..4eb8f75 100644 --- a/src/tokio.rs +++ b/src/tokio.rs @@ -9,7 +9,7 @@ //! ``` #[doc(inline)] -pub use core::{TokioChildWrapper, TokioCommandWrap, TokioCommandWrapper}; +pub use core::{ChildWrapper, CommandWrap, CommandWrapper}; #[cfg(all(windows, feature = "creation-flags"))] #[doc(inline)] pub use creation_flags::CreationFlags; diff --git a/src/tokio/core.rs b/src/tokio/core.rs index e3d232b..d06a149 100644 --- a/src/tokio/core.rs +++ b/src/tokio/core.rs @@ -17,14 +17,7 @@ use tokio::{ process::{Child, ChildStderr, ChildStdin, ChildStdout, Command}, }; -crate::generic_wrap::Wrap!( - TokioCommandWrap, - Command, - TokioCommandWrapper, - Child, - TokioChildWrapper, - |child| child -); +crate::generic_wrap::Wrap!(Command, Child, ChildWrapper, |child| child); /// Wrapper for `tokio::process::Child`. /// @@ -47,39 +40,39 @@ crate::generic_wrap::Wrap!( /// #[derive(Debug)] /// pub struct YourChildWrapper(Child); /// -/// impl TokioChildWrapper for YourChildWrapper { -/// fn inner(&self) -> &dyn TokioChildWrapper { +/// impl ChildWrapper for YourChildWrapper { +/// fn inner(&self) -> &dyn ChildWrapper { /// &self.0 /// } /// -/// fn inner_mut(&mut self) -> &mut dyn TokioChildWrapper { +/// fn inner_mut(&mut self) -> &mut dyn ChildWrapper { /// &mut self.0 /// } /// -/// fn into_inner(self: Box) -> Box { +/// fn into_inner(self: Box) -> Box { /// Box::new((*self).0) /// } /// } /// ``` -pub trait TokioChildWrapper: Any + std::fmt::Debug + Send { +pub trait ChildWrapper: Any + std::fmt::Debug + Send { /// Obtain a reference to the wrapped child. - fn inner(&self) -> &dyn TokioChildWrapper; + fn inner(&self) -> &dyn ChildWrapper; /// Obtain a mutable reference to the wrapped child. - fn inner_mut(&mut self) -> &mut dyn TokioChildWrapper; + fn inner_mut(&mut self) -> &mut dyn ChildWrapper; /// Consume the current wrapper and return the wrapped child. /// /// Note that this may disrupt whatever the current wrapper was doing. However, wrappers must /// ensure that the wrapped child is in a consistent state when this is called or they are /// dropped, so that this is always safe. - fn into_inner(self: Box) -> Box; + fn into_inner(self: Box) -> Box; /// Obtain a clone if possible. /// /// Some implementations may make it possible to clone the implementing structure, even though /// Tokio's `Child` isn't `Clone`. In those cases, this method should be overridden. - fn try_clone(&self) -> Option> { + fn try_clone(&self) -> Option> { None } @@ -206,14 +199,14 @@ pub trait TokioChildWrapper: Any + std::fmt::Debug + Send { } } -impl TokioChildWrapper for Child { - fn inner(&self) -> &dyn TokioChildWrapper { +impl ChildWrapper for Child { + fn inner(&self) -> &dyn ChildWrapper { self } - fn inner_mut(&mut self) -> &mut dyn TokioChildWrapper { + fn inner_mut(&mut self) -> &mut dyn ChildWrapper { self } - fn into_inner(self: Box) -> Box { + fn into_inner(self: Box) -> Box { Box::new(*self) } fn stdin(&mut self) -> &mut Option { @@ -251,7 +244,7 @@ impl TokioChildWrapper for Child { } } -impl dyn TokioChildWrapper { +impl dyn ChildWrapper { fn downcast_ref(&self) -> Option<&T> { (self as &dyn Any).downcast_ref() } diff --git a/src/tokio/creation_flags.rs b/src/tokio/creation_flags.rs index af9ebb4..f204b8a 100644 --- a/src/tokio/creation_flags.rs +++ b/src/tokio/creation_flags.rs @@ -3,7 +3,7 @@ use std::io::Result; use tokio::process::Command; use windows::Win32::System::Threading::PROCESS_CREATION_FLAGS; -use super::{TokioCommandWrap, TokioCommandWrapper}; +use super::{CommandWrap, CommandWrapper}; /// Shim wrapper which sets Windows process creation flags. /// diff --git a/src/tokio/job_object.rs b/src/tokio/job_object.rs index a5cf64a..fadd970 100644 --- a/src/tokio/job_object.rs +++ b/src/tokio/job_object.rs @@ -17,7 +17,7 @@ use crate::{ use super::CreationFlags; #[cfg(feature = "kill-on-drop")] use super::KillOnDrop; -use super::{TokioChildWrapper, TokioCommandWrap, TokioCommandWrapper}; +use super::{TokioChildWrapper, CommandWrap, CommandWrapper}; /// Wrapper which creates a job object context for a `Command`. /// diff --git a/src/tokio/kill_on_drop.rs b/src/tokio/kill_on_drop.rs index 84bc677..0eed5cf 100644 --- a/src/tokio/kill_on_drop.rs +++ b/src/tokio/kill_on_drop.rs @@ -2,7 +2,7 @@ use std::io::Result; use tokio::process::Command; -use super::{TokioCommandWrap, TokioCommandWrapper}; +use super::{CommandWrap, CommandWrapper}; /// Shim wrapper which sets kill-on-drop on a `Command`. /// @@ -12,8 +12,8 @@ use super::{TokioCommandWrap, TokioCommandWrapper}; #[derive(Clone, Copy, Debug)] pub struct KillOnDrop; -impl TokioCommandWrapper for KillOnDrop { - fn pre_spawn(&mut self, command: &mut Command, _core: &TokioCommandWrap) -> Result<()> { +impl CommandWrapper for KillOnDrop { + fn pre_spawn(&mut self, command: &mut Command, _core: &CommandWrap) -> Result<()> { command.kill_on_drop(true); Ok(()) } diff --git a/src/tokio/process_group.rs b/src/tokio/process_group.rs index 6b45255..118afcc 100644 --- a/src/tokio/process_group.rs +++ b/src/tokio/process_group.rs @@ -22,7 +22,7 @@ use tracing::instrument; use crate::ChildExitStatus; -use super::{TokioChildWrapper, TokioCommandWrap, TokioCommandWrapper}; +use super::{ChildWrapper, CommandWrap, CommandWrapper}; /// Wrapper which sets the process group of a `Command`. /// @@ -59,14 +59,14 @@ impl ProcessGroup { /// Wrapper for `Child` which ensures that all processes in the group are reaped. #[derive(Debug)] pub struct ProcessGroupChild { - inner: Box, + inner: Box, exit_status: ChildExitStatus, pgid: Pid, } impl ProcessGroupChild { #[cfg_attr(feature = "tracing", instrument(level = "debug"))] - pub(crate) fn new(inner: Box, pgid: Pid) -> Self { + pub(crate) fn new(inner: Box, pgid: Pid) -> Self { Self { inner, exit_status: ChildExitStatus::Running, @@ -82,9 +82,9 @@ impl ProcessGroupChild { } } -impl TokioCommandWrapper for ProcessGroup { +impl CommandWrapper for ProcessGroup { #[cfg_attr(feature = "tracing", instrument(level = "debug", skip(self)))] - fn pre_spawn(&mut self, command: &mut Command, _core: &TokioCommandWrap) -> Result<()> { + fn pre_spawn(&mut self, command: &mut Command, _core: &CommandWrap) -> Result<()> { command.process_group(self.leader.as_raw()); Ok(()) } @@ -92,9 +92,9 @@ impl TokioCommandWrapper for ProcessGroup { #[cfg_attr(feature = "tracing", instrument(level = "debug", skip(self)))] fn wrap_child( &mut self, - inner: Box, - _core: &TokioCommandWrap, - ) -> Result> { + inner: Box, + _core: &CommandWrap, + ) -> Result> { let pgid = Pid::from_raw( i32::try_from( inner @@ -159,14 +159,14 @@ impl ProcessGroupChild { } } -impl TokioChildWrapper for ProcessGroupChild { - fn inner(&self) -> &dyn TokioChildWrapper { +impl ChildWrapper for ProcessGroupChild { + fn inner(&self) -> &dyn ChildWrapper { self.inner.inner() } - fn inner_mut(&mut self) -> &mut dyn TokioChildWrapper { + fn inner_mut(&mut self) -> &mut dyn ChildWrapper { self.inner.inner_mut() } - fn into_inner(self: Box) -> Box { + fn into_inner(self: Box) -> Box { self.inner.into_inner() } diff --git a/src/tokio/process_session.rs b/src/tokio/process_session.rs index 5f4dfac..869e522 100644 --- a/src/tokio/process_session.rs +++ b/src/tokio/process_session.rs @@ -5,7 +5,7 @@ use tokio::process::Command; #[cfg(feature = "tracing")] use tracing::instrument; -use super::{TokioCommandWrap, TokioCommandWrapper}; +use super::{CommandWrap, CommandWrapper}; /// Wrapper which creates a new session and group for the `Command`. /// @@ -22,9 +22,9 @@ use super::{TokioCommandWrap, TokioCommandWrapper}; #[derive(Clone, Copy, Debug)] pub struct ProcessSession; -impl TokioCommandWrapper for ProcessSession { +impl CommandWrapper for ProcessSession { #[cfg_attr(feature = "tracing", instrument(level = "debug", skip(self)))] - fn pre_spawn(&mut self, command: &mut Command, _core: &TokioCommandWrap) -> Result<()> { + fn pre_spawn(&mut self, command: &mut Command, _core: &CommandWrap) -> Result<()> { unsafe { command.pre_exec(move || setsid().map_err(Error::from).map(|_| ())); } @@ -35,9 +35,9 @@ impl TokioCommandWrapper for ProcessSession { #[cfg_attr(feature = "tracing", instrument(level = "debug", skip(self)))] fn wrap_child( &mut self, - inner: Box, - _core: &TokioCommandWrap, - ) -> Result> { + inner: Box, + _core: &CommandWrap, + ) -> Result> { let pgid = Pid::from_raw( i32::try_from( inner diff --git a/src/tokio/reset_sigmask.rs b/src/tokio/reset_sigmask.rs index f9e25a2..0c9696a 100644 --- a/src/tokio/reset_sigmask.rs +++ b/src/tokio/reset_sigmask.rs @@ -5,7 +5,7 @@ use tokio::process::Command; #[cfg(feature = "tracing")] use tracing::trace; -use super::{TokioCommandWrap, TokioCommandWrapper}; +use super::{CommandWrap, CommandWrapper}; /// Wrapper which resets the process signal mask. /// @@ -14,8 +14,8 @@ use super::{TokioCommandWrap, TokioCommandWrapper}; #[derive(Clone, Copy, Debug)] pub struct ResetSigmask; -impl TokioCommandWrapper for ResetSigmask { - fn pre_spawn(&mut self, command: &mut Command, _core: &TokioCommandWrap) -> Result<()> { +impl CommandWrapper for ResetSigmask { + fn pre_spawn(&mut self, command: &mut Command, _core: &CommandWrap) -> Result<()> { unsafe { command.pre_exec(|| { let mut oldset = SigSet::empty(); diff --git a/tests/std_unix/id_same_as_inner.rs b/tests/std_unix/id_same_as_inner.rs index 1f70b1b..74060a2 100644 --- a/tests/std_unix/id_same_as_inner.rs +++ b/tests/std_unix/id_same_as_inner.rs @@ -2,7 +2,7 @@ use super::prelude::*; #[test] fn nowrap() -> Result<()> { - let child = StdCommandWrap::with_new("echo", |command| { + let child = CommandWrap::with_new("echo", |command| { command.stdout(Stdio::null()); }) .spawn()?; @@ -14,7 +14,7 @@ fn nowrap() -> Result<()> { #[test] fn process_group() -> Result<()> { - let child = StdCommandWrap::with_new("echo", |command| { + let child = CommandWrap::with_new("echo", |command| { command.stdout(Stdio::null()); }) .wrap(ProcessGroup::leader()) @@ -27,7 +27,7 @@ fn process_group() -> Result<()> { #[test] fn process_session() -> Result<()> { - let child = StdCommandWrap::with_new("echo", |command| { + let child = CommandWrap::with_new("echo", |command| { command.stdout(Stdio::null()); }) .wrap(ProcessSession) diff --git a/tests/std_unix/inner_read_stdout.rs b/tests/std_unix/inner_read_stdout.rs index 5857fc0..6288e2b 100644 --- a/tests/std_unix/inner_read_stdout.rs +++ b/tests/std_unix/inner_read_stdout.rs @@ -2,7 +2,7 @@ use super::prelude::*; #[test] fn nowrap() -> Result<()> { - let mut child = StdCommandWrap::with_new("echo", |command| { + let mut child = CommandWrap::with_new("echo", |command| { command.arg("hello").stdout(Stdio::piped()); }) .spawn()?; @@ -18,7 +18,7 @@ fn nowrap() -> Result<()> { #[test] fn process_group() -> Result<()> { - let mut child = StdCommandWrap::with_new("echo", |command| { + let mut child = CommandWrap::with_new("echo", |command| { command.arg("hello").stdout(Stdio::piped()); }) .wrap(ProcessGroup::leader()) @@ -35,7 +35,7 @@ fn process_group() -> Result<()> { #[test] fn process_session() -> Result<()> { - let mut child = StdCommandWrap::with_new("echo", |command| { + let mut child = CommandWrap::with_new("echo", |command| { command.arg("hello").stdout(Stdio::piped()); }) .wrap(ProcessSession) diff --git a/tests/std_unix/into_inner_write_stdin.rs b/tests/std_unix/into_inner_write_stdin.rs index d133e12..d5b48f8 100644 --- a/tests/std_unix/into_inner_write_stdin.rs +++ b/tests/std_unix/into_inner_write_stdin.rs @@ -3,7 +3,7 @@ use super::prelude::*; #[test] fn nowrap() -> Result<()> { let mut child = unsafe { - StdCommandWrap::with_new("cat", |command| { + CommandWrap::with_new("cat", |command| { command.stdin(Stdio::piped()).stdout(Stdio::piped()); }) .spawn()? @@ -26,7 +26,7 @@ fn nowrap() -> Result<()> { #[test] fn process_group() -> Result<()> { let mut child = unsafe { - StdCommandWrap::with_new("cat", |command| { + CommandWrap::with_new("cat", |command| { command.stdin(Stdio::piped()).stdout(Stdio::piped()); }) .wrap(ProcessGroup::leader()) @@ -50,7 +50,7 @@ fn process_group() -> Result<()> { #[test] fn process_session() -> Result<()> { let mut child = unsafe { - StdCommandWrap::with_new("cat", |command| { + CommandWrap::with_new("cat", |command| { command.stdin(Stdio::piped()).stdout(Stdio::piped()); }) .wrap(ProcessSession) diff --git a/tests/std_unix/kill_and_try_wait.rs b/tests/std_unix/kill_and_try_wait.rs index 4a95ee7..781cac0 100644 --- a/tests/std_unix/kill_and_try_wait.rs +++ b/tests/std_unix/kill_and_try_wait.rs @@ -2,7 +2,7 @@ use super::prelude::*; #[test] fn nowrap() -> Result<()> { - let mut child = StdCommandWrap::with_new("yes", |command| { + let mut child = CommandWrap::with_new("yes", |command| { command.stdout(Stdio::null()); }) .spawn()?; @@ -20,7 +20,7 @@ fn nowrap() -> Result<()> { #[test] fn process_group() -> Result<()> { - let mut child = StdCommandWrap::with_new("yes", |command| { + let mut child = CommandWrap::with_new("yes", |command| { command.stdout(Stdio::null()); }) .wrap(ProcessGroup::leader()) @@ -43,7 +43,7 @@ fn process_group() -> Result<()> { #[test] fn process_session() -> Result<()> { - let mut child = StdCommandWrap::with_new("yes", |command| { + let mut child = CommandWrap::with_new("yes", |command| { command.stdout(Stdio::null()); }) .wrap(ProcessSession) diff --git a/tests/std_unix/multiproc_linux.rs b/tests/std_unix/multiproc_linux.rs index ef82a48..c2d83af 100644 --- a/tests/std_unix/multiproc_linux.rs +++ b/tests/std_unix/multiproc_linux.rs @@ -4,7 +4,7 @@ use super::prelude::*; #[test] fn process_group_kill_leader() -> Result<()> { - let mut leader = StdCommandWrap::with_new("tests/multiproc_helper.rs", |command| { + let mut leader = CommandWrap::with_new("tests/multiproc_helper.rs", |command| { command .arg("1") .arg("10") @@ -46,7 +46,7 @@ fn process_group_kill_leader() -> Result<()> { #[test] fn process_group_kill_group() -> Result<()> { - let mut leader = StdCommandWrap::with_new("tests/multiproc_helper.rs", |command| { + let mut leader = CommandWrap::with_new("tests/multiproc_helper.rs", |command| { command .arg("1") .arg("10") @@ -89,7 +89,7 @@ fn process_group_kill_group() -> Result<()> { #[test] fn process_session_kill_leader() -> Result<()> { - let mut leader = StdCommandWrap::with_new("tests/multiproc_helper.rs", |command| { + let mut leader = CommandWrap::with_new("tests/multiproc_helper.rs", |command| { command .arg("1") .arg("10") @@ -131,7 +131,7 @@ fn process_session_kill_leader() -> Result<()> { #[test] fn process_session_kill_group() -> Result<()> { - let mut leader = StdCommandWrap::with_new("tests/multiproc_helper.rs", |command| { + let mut leader = CommandWrap::with_new("tests/multiproc_helper.rs", |command| { command .arg("1") .arg("10") diff --git a/tests/std_unix/signals.rs b/tests/std_unix/signals.rs index 71196de..b5f511f 100644 --- a/tests/std_unix/signals.rs +++ b/tests/std_unix/signals.rs @@ -2,7 +2,7 @@ use super::prelude::*; #[test] fn nowrap() -> Result<()> { - let mut child = StdCommandWrap::with_new("yes", |command| { + let mut child = CommandWrap::with_new("yes", |command| { command.stdout(Stdio::null()); }) .spawn()?; @@ -20,7 +20,7 @@ fn nowrap() -> Result<()> { #[test] fn process_group() -> Result<()> { - let mut child = StdCommandWrap::with_new("yes", |command| { + let mut child = CommandWrap::with_new("yes", |command| { command.stdout(Stdio::null()); }) .wrap(ProcessGroup::leader()) @@ -39,7 +39,7 @@ fn process_group() -> Result<()> { #[test] fn process_session() -> Result<()> { - let mut child = StdCommandWrap::with_new("yes", |command| { + let mut child = CommandWrap::with_new("yes", |command| { command.stdout(Stdio::null()); }) .wrap(ProcessSession) diff --git a/tests/std_unix/try_wait_after_die.rs b/tests/std_unix/try_wait_after_die.rs index fc203b1..afbf50f 100644 --- a/tests/std_unix/try_wait_after_die.rs +++ b/tests/std_unix/try_wait_after_die.rs @@ -2,7 +2,7 @@ use super::prelude::*; #[test] fn nowrap() -> Result<()> { - let mut child = StdCommandWrap::with_new("echo", |command| { + let mut child = CommandWrap::with_new("echo", |command| { command.stdout(Stdio::null()); }) .spawn()?; @@ -16,7 +16,7 @@ fn nowrap() -> Result<()> { #[test] fn process_group() -> Result<()> { - let mut child = StdCommandWrap::with_new("echo", |command| { + let mut child = CommandWrap::with_new("echo", |command| { command.stdout(Stdio::null()); }) .wrap(ProcessGroup::leader()) @@ -31,7 +31,7 @@ fn process_group() -> Result<()> { #[test] fn process_session() -> Result<()> { - let mut child = StdCommandWrap::with_new("echo", |command| { + let mut child = CommandWrap::with_new("echo", |command| { command.stdout(Stdio::null()); }) .wrap(ProcessSession) diff --git a/tests/std_unix/try_wait_twice_after_sigterm.rs b/tests/std_unix/try_wait_twice_after_sigterm.rs index 00f0a8e..c440216 100644 --- a/tests/std_unix/try_wait_twice_after_sigterm.rs +++ b/tests/std_unix/try_wait_twice_after_sigterm.rs @@ -2,7 +2,7 @@ use super::prelude::*; #[test] fn nowrap() -> Result<()> { - let mut child = StdCommandWrap::with_new("yes", |command| { + let mut child = CommandWrap::with_new("yes", |command| { command.stdout(Stdio::null()); }) .spawn()?; @@ -20,7 +20,7 @@ fn nowrap() -> Result<()> { #[test] fn process_group() -> Result<()> { - let mut child = StdCommandWrap::with_new("yes", |command| { + let mut child = CommandWrap::with_new("yes", |command| { command.stdout(Stdio::null()); }) .wrap(ProcessGroup::leader()) @@ -39,7 +39,7 @@ fn process_group() -> Result<()> { #[test] fn process_session() -> Result<()> { - let mut child = StdCommandWrap::with_new("yes", |command| { + let mut child = CommandWrap::with_new("yes", |command| { command.stdout(Stdio::null()); }) .wrap(ProcessSession) diff --git a/tests/std_unix/wait_after_die.rs b/tests/std_unix/wait_after_die.rs index 7cc71ed..078b71c 100644 --- a/tests/std_unix/wait_after_die.rs +++ b/tests/std_unix/wait_after_die.rs @@ -2,7 +2,7 @@ use super::prelude::*; #[test] fn nowrap() -> Result<()> { - let mut child = StdCommandWrap::with_new("echo", |command| { + let mut child = CommandWrap::with_new("echo", |command| { command.stdout(Stdio::null()); }) .spawn()?; @@ -16,7 +16,7 @@ fn nowrap() -> Result<()> { #[test] fn process_group() -> Result<()> { - let mut child = StdCommandWrap::with_new("echo", |command| { + let mut child = CommandWrap::with_new("echo", |command| { command.stdout(Stdio::null()); }) .wrap(ProcessGroup::leader()) @@ -31,7 +31,7 @@ fn process_group() -> Result<()> { #[test] fn process_session() -> Result<()> { - let mut child = StdCommandWrap::with_new("echo", |command| { + let mut child = CommandWrap::with_new("echo", |command| { command.stdout(Stdio::null()); }) .wrap(ProcessSession) diff --git a/tests/std_unix/wait_twice.rs b/tests/std_unix/wait_twice.rs index c2cfffd..a089b8f 100644 --- a/tests/std_unix/wait_twice.rs +++ b/tests/std_unix/wait_twice.rs @@ -2,7 +2,7 @@ use super::prelude::*; #[test] fn nowrap() -> Result<()> { - let mut child = StdCommandWrap::with_new("echo", |command| { + let mut child = CommandWrap::with_new("echo", |command| { command.stdout(Stdio::null()); }) .spawn()?; @@ -18,7 +18,7 @@ fn nowrap() -> Result<()> { #[test] fn process_group() -> Result<()> { - let mut child = StdCommandWrap::with_new("echo", |command| { + let mut child = CommandWrap::with_new("echo", |command| { command.stdout(Stdio::null()); }) .wrap(ProcessGroup::leader()) @@ -35,7 +35,7 @@ fn process_group() -> Result<()> { #[test] fn process_session() -> Result<()> { - let mut child = StdCommandWrap::with_new("echo", |command| { + let mut child = CommandWrap::with_new("echo", |command| { command.stdout(Stdio::null()); }) .wrap(ProcessSession) diff --git a/tests/std_unix/wait_twice_after_sigterm.rs b/tests/std_unix/wait_twice_after_sigterm.rs index 7cb5165..aa57728 100644 --- a/tests/std_unix/wait_twice_after_sigterm.rs +++ b/tests/std_unix/wait_twice_after_sigterm.rs @@ -2,7 +2,7 @@ use super::prelude::*; #[test] fn nowrap() -> Result<()> { - let mut child = StdCommandWrap::with_new("yes", |command| { + let mut child = CommandWrap::with_new("yes", |command| { command.stdout(Stdio::null()); }) .spawn()?; @@ -21,7 +21,7 @@ fn nowrap() -> Result<()> { #[test] fn process_group() -> Result<()> { - let mut child = StdCommandWrap::with_new("yes", |command| { + let mut child = CommandWrap::with_new("yes", |command| { command.stdout(Stdio::null()); }) .wrap(ProcessGroup::leader()) @@ -41,7 +41,7 @@ fn process_group() -> Result<()> { #[test] fn process_session() -> Result<()> { - let mut child = StdCommandWrap::with_new("yes", |command| { + let mut child = CommandWrap::with_new("yes", |command| { command.stdout(Stdio::null()); }) .wrap(ProcessSession) diff --git a/tests/std_unix/wait_with_output.rs b/tests/std_unix/wait_with_output.rs index ab5d2c6..1285b7a 100644 --- a/tests/std_unix/wait_with_output.rs +++ b/tests/std_unix/wait_with_output.rs @@ -2,7 +2,7 @@ use super::prelude::*; #[test] fn nowrap() -> Result<()> { - let child = StdCommandWrap::with_new("echo", |command| { + let child = CommandWrap::with_new("echo", |command| { command.arg("hello").stdout(Stdio::piped()); }) .spawn()?; @@ -16,7 +16,7 @@ fn nowrap() -> Result<()> { #[test] fn process_group() -> Result<()> { - let child = StdCommandWrap::with_new("echo", |command| { + let child = CommandWrap::with_new("echo", |command| { command.arg("hello").stdout(Stdio::piped()); }) .wrap(ProcessGroup::leader()) @@ -31,7 +31,7 @@ fn process_group() -> Result<()> { #[test] fn process_session() -> Result<()> { - let child = StdCommandWrap::with_new("echo", |command| { + let child = CommandWrap::with_new("echo", |command| { command.arg("hello").stdout(Stdio::piped()); }) .wrap(ProcessSession) diff --git a/tests/std_windows/id_same_as_inner.rs b/tests/std_windows/id_same_as_inner.rs index 16c8604..c59d369 100644 --- a/tests/std_windows/id_same_as_inner.rs +++ b/tests/std_windows/id_same_as_inner.rs @@ -2,7 +2,7 @@ use super::prelude::*; #[test] fn nowrap() -> Result<()> { - let child = StdCommandWrap::with_new("powershell.exe", |command| { + let child = CommandWrap::with_new("powershell.exe", |command| { command.arg("/C").arg("echo hello").stdout(Stdio::null()); }) .spawn()?; @@ -14,7 +14,7 @@ fn nowrap() -> Result<()> { #[test] fn job_object() -> Result<()> { - let child = StdCommandWrap::with_new("powershell.exe", |command| { + let child = CommandWrap::with_new("powershell.exe", |command| { command.arg("/C").arg("echo hello").stdout(Stdio::null()); }) .wrap(JobObject) diff --git a/tests/std_windows/inner_read_stdout.rs b/tests/std_windows/inner_read_stdout.rs index 34a1ad4..668ad31 100644 --- a/tests/std_windows/inner_read_stdout.rs +++ b/tests/std_windows/inner_read_stdout.rs @@ -2,7 +2,7 @@ use super::prelude::*; #[test] fn nowrap() -> Result<()> { - let mut child = StdCommandWrap::with_new("powershell.exe", |command| { + let mut child = CommandWrap::with_new("powershell.exe", |command| { command.arg("/C").arg("echo hello").stdout(Stdio::piped()); }) .spawn()?; @@ -18,7 +18,7 @@ fn nowrap() -> Result<()> { #[test] fn job_object() -> Result<()> { - let mut child = StdCommandWrap::with_new("powershell.exe", |command| { + let mut child = CommandWrap::with_new("powershell.exe", |command| { command.arg("/C").arg("echo hello").stdout(Stdio::piped()); }) .wrap(JobObject) diff --git a/tests/std_windows/into_inner_write_stdin.rs b/tests/std_windows/into_inner_write_stdin.rs index d19f74d..3cb934f 100644 --- a/tests/std_windows/into_inner_write_stdin.rs +++ b/tests/std_windows/into_inner_write_stdin.rs @@ -2,7 +2,7 @@ use super::prelude::*; #[test] fn nowrap() -> Result<()> { - let mut child = StdCommandWrap::with_new("findstr", |command| { + let mut child = CommandWrap::with_new("findstr", |command| { command .arg("^") .stdin(Stdio::piped()) @@ -26,7 +26,7 @@ fn nowrap() -> Result<()> { #[test] fn job_object() -> Result<()> { - let mut child = StdCommandWrap::with_new("findstr", |command| { + let mut child = CommandWrap::with_new("findstr", |command| { command .arg("^") .stdin(Stdio::piped()) diff --git a/tests/std_windows/kill_and_try_wait.rs b/tests/std_windows/kill_and_try_wait.rs index a8b8c67..2f0b03d 100644 --- a/tests/std_windows/kill_and_try_wait.rs +++ b/tests/std_windows/kill_and_try_wait.rs @@ -2,7 +2,7 @@ use super::prelude::*; #[test] fn nowrap() -> Result<()> { - let mut child = StdCommandWrap::with_new("powershell.exe", |command| { + let mut child = CommandWrap::with_new("powershell.exe", |command| { command.arg("/C").arg("pause").stdout(Stdio::null()); }) .spawn()?; @@ -20,7 +20,7 @@ fn nowrap() -> Result<()> { #[test] fn job_object() -> Result<()> { - let mut child = StdCommandWrap::with_new("powershell.exe", |command| { + let mut child = CommandWrap::with_new("powershell.exe", |command| { command.arg("/C").arg("pause").stdout(Stdio::null()); }) .wrap(JobObject) diff --git a/tests/std_windows/try_wait_after_die.rs b/tests/std_windows/try_wait_after_die.rs index 2d8a927..de2e05e 100644 --- a/tests/std_windows/try_wait_after_die.rs +++ b/tests/std_windows/try_wait_after_die.rs @@ -2,7 +2,7 @@ use super::prelude::*; #[test] fn nowrap() -> Result<()> { - let mut child = StdCommandWrap::with_new("powershell.exe", |command| { + let mut child = CommandWrap::with_new("powershell.exe", |command| { command.arg("/C").arg("echo hello").stdout(Stdio::null()); }) .spawn()?; @@ -16,7 +16,7 @@ fn nowrap() -> Result<()> { #[test] fn job_object() -> Result<()> { - let mut child = StdCommandWrap::with_new("powershell.exe", |command| { + let mut child = CommandWrap::with_new("powershell.exe", |command| { command.arg("/C").arg("echo hello").stdout(Stdio::null()); }) .wrap(JobObject) diff --git a/tests/std_windows/wait_after_die.rs b/tests/std_windows/wait_after_die.rs index 70264d8..a9cbc0f 100644 --- a/tests/std_windows/wait_after_die.rs +++ b/tests/std_windows/wait_after_die.rs @@ -2,7 +2,7 @@ use super::prelude::*; #[test] fn nowrap() -> Result<()> { - let mut child = StdCommandWrap::with_new("powershell.exe", |command| { + let mut child = CommandWrap::with_new("powershell.exe", |command| { command.arg("/C").arg("echo hello").stdout(Stdio::null()); }) .spawn()?; @@ -16,7 +16,7 @@ fn nowrap() -> Result<()> { #[test] fn job_object() -> Result<()> { - let mut child = StdCommandWrap::with_new("powershell.exe", |command| { + let mut child = CommandWrap::with_new("powershell.exe", |command| { command.arg("/C").arg("echo hello").stdout(Stdio::null()); }) .wrap(JobObject) diff --git a/tests/std_windows/wait_twice.rs b/tests/std_windows/wait_twice.rs index 8496306..b103523 100644 --- a/tests/std_windows/wait_twice.rs +++ b/tests/std_windows/wait_twice.rs @@ -2,7 +2,7 @@ use super::prelude::*; #[test] fn nowrap() -> Result<()> { - let mut child = StdCommandWrap::with_new("powershell.exe", |command| { + let mut child = CommandWrap::with_new("powershell.exe", |command| { command.arg("/C").arg("echo hello").stdout(Stdio::null()); }) .spawn()?; @@ -18,7 +18,7 @@ fn nowrap() -> Result<()> { #[test] fn job_object() -> Result<()> { - let mut child = StdCommandWrap::with_new("powershell.exe", |command| { + let mut child = CommandWrap::with_new("powershell.exe", |command| { command.arg("/C").arg("echo hello").stdout(Stdio::null()); }) .wrap(JobObject) diff --git a/tests/std_windows/wait_with_output.rs b/tests/std_windows/wait_with_output.rs index 91a7092..dd3a04c 100644 --- a/tests/std_windows/wait_with_output.rs +++ b/tests/std_windows/wait_with_output.rs @@ -2,7 +2,7 @@ use super::prelude::*; #[test] fn nowrap() -> Result<()> { - let child = StdCommandWrap::with_new("powershell.exe", |command| { + let child = CommandWrap::with_new("powershell.exe", |command| { command.arg("/C").arg("echo hello").stdout(Stdio::piped()); }) .spawn()?; @@ -16,7 +16,7 @@ fn nowrap() -> Result<()> { #[test] fn job_object() -> Result<()> { - let child = StdCommandWrap::with_new("powershell.exe", |command| { + let child = CommandWrap::with_new("powershell.exe", |command| { command.arg("/C").arg("echo hello").stdout(Stdio::piped()); }) .wrap(JobObject) diff --git a/tests/tokio_unix/id_same_as_inner.rs b/tests/tokio_unix/id_same_as_inner.rs index a57c147..2459495 100644 --- a/tests/tokio_unix/id_same_as_inner.rs +++ b/tests/tokio_unix/id_same_as_inner.rs @@ -2,7 +2,7 @@ use super::prelude::*; #[tokio::test] async fn nowrap() -> Result<()> { - let child = TokioCommandWrap::with_new("echo", |command| { + let child = CommandWrap::with_new("echo", |command| { command.stdout(Stdio::null()); }) .spawn()?; @@ -14,7 +14,7 @@ async fn nowrap() -> Result<()> { #[tokio::test] async fn process_group() -> Result<()> { - let child = TokioCommandWrap::with_new("echo", |command| { + let child = CommandWrap::with_new("echo", |command| { command.stdout(Stdio::null()); }) .wrap(ProcessGroup::leader()) @@ -27,7 +27,7 @@ async fn process_group() -> Result<()> { #[tokio::test] async fn process_session() -> Result<()> { - let child = TokioCommandWrap::with_new("echo", |command| { + let child = CommandWrap::with_new("echo", |command| { command.stdout(Stdio::null()); }) .wrap(ProcessSession) diff --git a/tests/tokio_unix/inner_read_stdout.rs b/tests/tokio_unix/inner_read_stdout.rs index 8b339c9..22ff018 100644 --- a/tests/tokio_unix/inner_read_stdout.rs +++ b/tests/tokio_unix/inner_read_stdout.rs @@ -2,7 +2,7 @@ use super::prelude::*; #[tokio::test] async fn nowrap() -> Result<()> { - let mut child = TokioCommandWrap::with_new("echo", |command| { + let mut child = CommandWrap::with_new("echo", |command| { command.arg("hello").stdout(Stdio::piped()); }) .spawn()?; @@ -18,7 +18,7 @@ async fn nowrap() -> Result<()> { #[tokio::test] async fn process_group() -> Result<()> { - let mut child = TokioCommandWrap::with_new("echo", |command| { + let mut child = CommandWrap::with_new("echo", |command| { command.arg("hello").stdout(Stdio::piped()); }) .wrap(ProcessGroup::leader()) @@ -35,7 +35,7 @@ async fn process_group() -> Result<()> { #[tokio::test] async fn process_session() -> Result<()> { - let mut child = TokioCommandWrap::with_new("echo", |command| { + let mut child = CommandWrap::with_new("echo", |command| { command.arg("hello").stdout(Stdio::piped()); }) .wrap(ProcessSession) diff --git a/tests/tokio_unix/into_inner_write_stdin.rs b/tests/tokio_unix/into_inner_write_stdin.rs index 64de677..ecd1a0f 100644 --- a/tests/tokio_unix/into_inner_write_stdin.rs +++ b/tests/tokio_unix/into_inner_write_stdin.rs @@ -2,7 +2,7 @@ use super::prelude::*; #[tokio::test] async fn nowrap() -> Result<()> { - let mut child = TokioCommandWrap::with_new("cat", |command| { + let mut child = CommandWrap::with_new("cat", |command| { command.stdin(Stdio::piped()).stdout(Stdio::piped()); }) .spawn()? @@ -23,7 +23,7 @@ async fn nowrap() -> Result<()> { #[tokio::test] async fn process_group() -> Result<()> { - let mut child = TokioCommandWrap::with_new("cat", |command| { + let mut child = CommandWrap::with_new("cat", |command| { command.stdin(Stdio::piped()).stdout(Stdio::piped()); }) .wrap(ProcessGroup::leader()) @@ -45,7 +45,7 @@ async fn process_group() -> Result<()> { #[tokio::test] async fn process_session() -> Result<()> { - let mut child = TokioCommandWrap::with_new("cat", |command| { + let mut child = CommandWrap::with_new("cat", |command| { command.stdin(Stdio::piped()).stdout(Stdio::piped()); }) .wrap(ProcessSession) diff --git a/tests/tokio_unix/kill_and_try_wait.rs b/tests/tokio_unix/kill_and_try_wait.rs index 2c25466..001aca9 100644 --- a/tests/tokio_unix/kill_and_try_wait.rs +++ b/tests/tokio_unix/kill_and_try_wait.rs @@ -2,7 +2,7 @@ use super::prelude::*; #[tokio::test] async fn nowrap() -> Result<()> { - let mut child = TokioCommandWrap::with_new("yes", |command| { + let mut child = CommandWrap::with_new("yes", |command| { command.stdout(Stdio::null()); }) .spawn()?; @@ -20,7 +20,7 @@ async fn nowrap() -> Result<()> { #[tokio::test] async fn process_group() -> Result<()> { - let mut child = TokioCommandWrap::with_new("yes", |command| { + let mut child = CommandWrap::with_new("yes", |command| { command.stdout(Stdio::null()); }) .wrap(ProcessGroup::leader()) @@ -43,7 +43,7 @@ async fn process_group() -> Result<()> { #[tokio::test] async fn process_session() -> Result<()> { - let mut child = TokioCommandWrap::with_new("yes", |command| { + let mut child = CommandWrap::with_new("yes", |command| { command.stdout(Stdio::null()); }) .wrap(ProcessSession) diff --git a/tests/tokio_unix/multiproc_linux.rs b/tests/tokio_unix/multiproc_linux.rs index fa41499..f13c448 100644 --- a/tests/tokio_unix/multiproc_linux.rs +++ b/tests/tokio_unix/multiproc_linux.rs @@ -4,7 +4,7 @@ use super::prelude::*; #[tokio::test] async fn process_group_kill_leader() -> Result<()> { - let mut leader = TokioCommandWrap::with_new("tests/multiproc_helper.rs", |command| { + let mut leader = CommandWrap::with_new("tests/multiproc_helper.rs", |command| { command .arg("1") .arg("10") @@ -47,7 +47,7 @@ async fn process_group_kill_leader() -> Result<()> { #[tokio::test] async fn process_group_kill_group() -> Result<()> { - let mut leader = TokioCommandWrap::with_new("tests/multiproc_helper.rs", |command| { + let mut leader = CommandWrap::with_new("tests/multiproc_helper.rs", |command| { command .arg("1") .arg("10") @@ -91,7 +91,7 @@ async fn process_group_kill_group() -> Result<()> { #[tokio::test] async fn process_session_kill_leader() -> Result<()> { - let mut leader = TokioCommandWrap::with_new("tests/multiproc_helper.rs", |command| { + let mut leader = CommandWrap::with_new("tests/multiproc_helper.rs", |command| { command .arg("1") .arg("10") @@ -134,7 +134,7 @@ async fn process_session_kill_leader() -> Result<()> { #[tokio::test] async fn process_session_kill_group() -> Result<()> { - let mut leader = TokioCommandWrap::with_new("tests/multiproc_helper.rs", |command| { + let mut leader = CommandWrap::with_new("tests/multiproc_helper.rs", |command| { command .arg("1") .arg("10") diff --git a/tests/tokio_unix/signals.rs b/tests/tokio_unix/signals.rs index 4de5e71..124635c 100644 --- a/tests/tokio_unix/signals.rs +++ b/tests/tokio_unix/signals.rs @@ -2,7 +2,7 @@ use super::prelude::*; #[tokio::test] async fn nowrap() -> Result<()> { - let mut child = TokioCommandWrap::with_new("yes", |command| { + let mut child = CommandWrap::with_new("yes", |command| { command.stdout(Stdio::null()); }) .spawn()?; @@ -20,7 +20,7 @@ async fn nowrap() -> Result<()> { #[tokio::test] async fn process_group() -> Result<()> { - let mut child = TokioCommandWrap::with_new("yes", |command| { + let mut child = CommandWrap::with_new("yes", |command| { command.stdout(Stdio::null()); }) .wrap(ProcessGroup::leader()) @@ -39,7 +39,7 @@ async fn process_group() -> Result<()> { #[tokio::test] async fn process_session() -> Result<()> { - let mut child = TokioCommandWrap::with_new("yes", |command| { + let mut child = CommandWrap::with_new("yes", |command| { command.stdout(Stdio::null()); }) .wrap(ProcessSession) diff --git a/tests/tokio_unix/try_wait_after_die.rs b/tests/tokio_unix/try_wait_after_die.rs index 97efda9..f23bc83 100644 --- a/tests/tokio_unix/try_wait_after_die.rs +++ b/tests/tokio_unix/try_wait_after_die.rs @@ -2,7 +2,7 @@ use super::prelude::*; #[tokio::test] async fn nowrap() -> Result<()> { - let mut child = TokioCommandWrap::with_new("echo", |command| { + let mut child = CommandWrap::with_new("echo", |command| { command.stdout(Stdio::null()); }) .spawn()?; @@ -16,7 +16,7 @@ async fn nowrap() -> Result<()> { #[tokio::test] async fn process_group() -> Result<()> { - let mut child = TokioCommandWrap::with_new("echo", |command| { + let mut child = CommandWrap::with_new("echo", |command| { command.stdout(Stdio::null()); }) .wrap(ProcessGroup::leader()) @@ -31,7 +31,7 @@ async fn process_group() -> Result<()> { #[tokio::test] async fn process_session() -> Result<()> { - let mut child = TokioCommandWrap::with_new("echo", |command| { + let mut child = CommandWrap::with_new("echo", |command| { command.stdout(Stdio::null()); }) .wrap(ProcessSession) diff --git a/tests/tokio_unix/try_wait_twice_after_sigterm.rs b/tests/tokio_unix/try_wait_twice_after_sigterm.rs index 39a0415..455b0b4 100644 --- a/tests/tokio_unix/try_wait_twice_after_sigterm.rs +++ b/tests/tokio_unix/try_wait_twice_after_sigterm.rs @@ -2,7 +2,7 @@ use super::prelude::*; #[tokio::test] async fn nowrap() -> Result<()> { - let mut child = TokioCommandWrap::with_new("yes", |command| { + let mut child = CommandWrap::with_new("yes", |command| { command.stdout(Stdio::null()); }) .spawn()?; @@ -20,7 +20,7 @@ async fn nowrap() -> Result<()> { #[tokio::test] async fn process_group() -> Result<()> { - let mut child = TokioCommandWrap::with_new("yes", |command| { + let mut child = CommandWrap::with_new("yes", |command| { command.stdout(Stdio::null()); }) .wrap(ProcessGroup::leader()) @@ -39,7 +39,7 @@ async fn process_group() -> Result<()> { #[tokio::test] async fn process_session() -> Result<()> { - let mut child = TokioCommandWrap::with_new("yes", |command| { + let mut child = CommandWrap::with_new("yes", |command| { command.stdout(Stdio::null()); }) .wrap(ProcessSession) diff --git a/tests/tokio_unix/wait_after_die.rs b/tests/tokio_unix/wait_after_die.rs index f1c85f7..4c017a2 100644 --- a/tests/tokio_unix/wait_after_die.rs +++ b/tests/tokio_unix/wait_after_die.rs @@ -2,7 +2,7 @@ use super::prelude::*; #[tokio::test] async fn nowrap() -> Result<()> { - let mut child = TokioCommandWrap::with_new("echo", |command| { + let mut child = CommandWrap::with_new("echo", |command| { command.stdout(Stdio::null()); }) .spawn()?; @@ -16,7 +16,7 @@ async fn nowrap() -> Result<()> { #[tokio::test] async fn process_group() -> Result<()> { - let mut child = TokioCommandWrap::with_new("echo", |command| { + let mut child = CommandWrap::with_new("echo", |command| { command.stdout(Stdio::null()); }) .wrap(ProcessGroup::leader()) @@ -31,7 +31,7 @@ async fn process_group() -> Result<()> { #[tokio::test] async fn process_session() -> Result<()> { - let mut child = TokioCommandWrap::with_new("echo", |command| { + let mut child = CommandWrap::with_new("echo", |command| { command.stdout(Stdio::null()); }) .wrap(ProcessSession) diff --git a/tests/tokio_unix/wait_twice.rs b/tests/tokio_unix/wait_twice.rs index 3560cb4..47dfdd7 100644 --- a/tests/tokio_unix/wait_twice.rs +++ b/tests/tokio_unix/wait_twice.rs @@ -2,7 +2,7 @@ use super::prelude::*; #[tokio::test] async fn nowrap() -> Result<()> { - let mut child = TokioCommandWrap::with_new("echo", |command| { + let mut child = CommandWrap::with_new("echo", |command| { command.stdout(Stdio::null()); }) .spawn()?; @@ -18,7 +18,7 @@ async fn nowrap() -> Result<()> { #[tokio::test] async fn process_group() -> Result<()> { - let mut child = TokioCommandWrap::with_new("echo", |command| { + let mut child = CommandWrap::with_new("echo", |command| { command.stdout(Stdio::null()); }) .wrap(ProcessGroup::leader()) @@ -35,7 +35,7 @@ async fn process_group() -> Result<()> { #[tokio::test] async fn process_session() -> Result<()> { - let mut child = TokioCommandWrap::with_new("echo", |command| { + let mut child = CommandWrap::with_new("echo", |command| { command.stdout(Stdio::null()); }) .wrap(ProcessSession) diff --git a/tests/tokio_unix/wait_twice_after_sigterm.rs b/tests/tokio_unix/wait_twice_after_sigterm.rs index e72b4a9..a6b5a53 100644 --- a/tests/tokio_unix/wait_twice_after_sigterm.rs +++ b/tests/tokio_unix/wait_twice_after_sigterm.rs @@ -2,7 +2,7 @@ use super::prelude::*; #[tokio::test] async fn nowrap() -> Result<()> { - let mut child = TokioCommandWrap::with_new("yes", |command| { + let mut child = CommandWrap::with_new("yes", |command| { command.stdout(Stdio::null()); }) .spawn()?; @@ -21,7 +21,7 @@ async fn nowrap() -> Result<()> { #[tokio::test] async fn process_group() -> Result<()> { - let mut child = TokioCommandWrap::with_new("yes", |command| { + let mut child = CommandWrap::with_new("yes", |command| { command.stdout(Stdio::null()); }) .wrap(ProcessGroup::leader()) @@ -41,7 +41,7 @@ async fn process_group() -> Result<()> { #[tokio::test] async fn process_session() -> Result<()> { - let mut child = TokioCommandWrap::with_new("yes", |command| { + let mut child = CommandWrap::with_new("yes", |command| { command.stdout(Stdio::null()); }) .wrap(ProcessSession) diff --git a/tests/tokio_unix/wait_with_output.rs b/tests/tokio_unix/wait_with_output.rs index b414fff..e15771c 100644 --- a/tests/tokio_unix/wait_with_output.rs +++ b/tests/tokio_unix/wait_with_output.rs @@ -2,7 +2,7 @@ use super::prelude::*; #[tokio::test] async fn nowrap() -> Result<()> { - let child = TokioCommandWrap::with_new("echo", |command| { + let child = CommandWrap::with_new("echo", |command| { command.arg("hello").stdout(Stdio::piped()); }) .spawn()?; @@ -16,7 +16,7 @@ async fn nowrap() -> Result<()> { #[tokio::test] async fn process_group() -> Result<()> { - let child = TokioCommandWrap::with_new("echo", |command| { + let child = CommandWrap::with_new("echo", |command| { command.arg("hello").stdout(Stdio::piped()); }) .wrap(ProcessGroup::leader()) @@ -31,7 +31,7 @@ async fn process_group() -> Result<()> { #[tokio::test] async fn process_session() -> Result<()> { - let child = TokioCommandWrap::with_new("echo", |command| { + let child = CommandWrap::with_new("echo", |command| { command.arg("hello").stdout(Stdio::piped()); }) .wrap(ProcessSession) diff --git a/tests/tokio_windows/id_same_as_inner.rs b/tests/tokio_windows/id_same_as_inner.rs index 8b6dbfd..6d2504d 100644 --- a/tests/tokio_windows/id_same_as_inner.rs +++ b/tests/tokio_windows/id_same_as_inner.rs @@ -2,7 +2,7 @@ use super::prelude::*; #[tokio::test] async fn nowrap() -> Result<()> { - let child = TokioCommandWrap::with_new("powershell.exe", |command| { + let child = CommandWrap::with_new("powershell.exe", |command| { command.arg("/C").arg("echo hello").stdout(Stdio::null()); }) .spawn()?; @@ -14,7 +14,7 @@ async fn nowrap() -> Result<()> { #[tokio::test] async fn job_object() -> Result<()> { - let child = TokioCommandWrap::with_new("powershell.exe", |command| { + let child = CommandWrap::with_new("powershell.exe", |command| { command.arg("/C").arg("echo hello").stdout(Stdio::null()); }) .wrap(JobObject) diff --git a/tests/tokio_windows/inner_read_stdout.rs b/tests/tokio_windows/inner_read_stdout.rs index 7a483b6..3d9a487 100644 --- a/tests/tokio_windows/inner_read_stdout.rs +++ b/tests/tokio_windows/inner_read_stdout.rs @@ -2,7 +2,7 @@ use super::prelude::*; #[tokio::test] async fn nowrap() -> Result<()> { - let mut child = TokioCommandWrap::with_new("powershell.exe", |command| { + let mut child = CommandWrap::with_new("powershell.exe", |command| { command.arg("/C").arg("echo hello").stdout(Stdio::piped()); }) .spawn()?; @@ -18,7 +18,7 @@ async fn nowrap() -> Result<()> { #[tokio::test] async fn job_object() -> Result<()> { - let mut child = TokioCommandWrap::with_new("powershell.exe", |command| { + let mut child = CommandWrap::with_new("powershell.exe", |command| { command.arg("/C").arg("echo hello").stdout(Stdio::piped()); }) .wrap(JobObject) diff --git a/tests/tokio_windows/into_inner_write_stdin.rs b/tests/tokio_windows/into_inner_write_stdin.rs index ac4017b..b278973 100644 --- a/tests/tokio_windows/into_inner_write_stdin.rs +++ b/tests/tokio_windows/into_inner_write_stdin.rs @@ -2,7 +2,7 @@ use super::prelude::*; #[tokio::test] async fn nowrap() -> Result<()> { - let mut child = TokioCommandWrap::with_new("findstr", |command| { + let mut child = CommandWrap::with_new("findstr", |command| { command .arg("^") .stdin(Stdio::piped()) @@ -26,7 +26,7 @@ async fn nowrap() -> Result<()> { #[tokio::test] async fn job_object() -> Result<()> { - let mut child = TokioCommandWrap::with_new("findstr", |command| { + let mut child = CommandWrap::with_new("findstr", |command| { command .arg("^") .stdin(Stdio::piped()) diff --git a/tests/tokio_windows/kill_and_try_wait.rs b/tests/tokio_windows/kill_and_try_wait.rs index 01fb426..e0e42cc 100644 --- a/tests/tokio_windows/kill_and_try_wait.rs +++ b/tests/tokio_windows/kill_and_try_wait.rs @@ -2,7 +2,7 @@ use super::prelude::*; #[tokio::test] async fn nowrap() -> Result<()> { - let mut child = TokioCommandWrap::with_new("powershell.exe", |command| { + let mut child = CommandWrap::with_new("powershell.exe", |command| { command.arg("/C").arg("pause").stdout(Stdio::null()); }) .spawn()?; @@ -20,7 +20,7 @@ async fn nowrap() -> Result<()> { #[tokio::test] async fn job_object() -> Result<()> { - let mut child = TokioCommandWrap::with_new("powershell.exe", |command| { + let mut child = CommandWrap::with_new("powershell.exe", |command| { command.arg("/C").arg("pause").stdout(Stdio::null()); }) .wrap(JobObject) diff --git a/tests/tokio_windows/try_wait_after_die.rs b/tests/tokio_windows/try_wait_after_die.rs index d24fe18..1ed70c6 100644 --- a/tests/tokio_windows/try_wait_after_die.rs +++ b/tests/tokio_windows/try_wait_after_die.rs @@ -2,7 +2,7 @@ use super::prelude::*; #[tokio::test] async fn nowrap() -> Result<()> { - let mut child = TokioCommandWrap::with_new("powershell.exe", |command| { + let mut child = CommandWrap::with_new("powershell.exe", |command| { command.arg("/C").arg("echo hello").stdout(Stdio::null()); }) .spawn()?; @@ -16,7 +16,7 @@ async fn nowrap() -> Result<()> { #[tokio::test] async fn job_object() -> Result<()> { - let mut child = TokioCommandWrap::with_new("powershell.exe", |command| { + let mut child = CommandWrap::with_new("powershell.exe", |command| { command.arg("/C").arg("echo hello").stdout(Stdio::null()); }) .wrap(JobObject) diff --git a/tests/tokio_windows/wait_after_die.rs b/tests/tokio_windows/wait_after_die.rs index 0b1f840..28e12b1 100644 --- a/tests/tokio_windows/wait_after_die.rs +++ b/tests/tokio_windows/wait_after_die.rs @@ -2,7 +2,7 @@ use super::prelude::*; #[tokio::test] async fn nowrap() -> Result<()> { - let mut child = TokioCommandWrap::with_new("powershell.exe", |command| { + let mut child = CommandWrap::with_new("powershell.exe", |command| { command.arg("/C").arg("echo hello").stdout(Stdio::null()); }) .spawn()?; @@ -16,7 +16,7 @@ async fn nowrap() -> Result<()> { #[tokio::test] async fn job_object() -> Result<()> { - let mut child = TokioCommandWrap::with_new("powershell.exe", |command| { + let mut child = CommandWrap::with_new("powershell.exe", |command| { command.arg("/C").arg("echo hello").stdout(Stdio::null()); }) .wrap(JobObject) diff --git a/tests/tokio_windows/wait_twice.rs b/tests/tokio_windows/wait_twice.rs index c79e9e6..d20241a 100644 --- a/tests/tokio_windows/wait_twice.rs +++ b/tests/tokio_windows/wait_twice.rs @@ -2,7 +2,7 @@ use super::prelude::*; #[tokio::test] async fn nowrap() -> Result<()> { - let mut child = TokioCommandWrap::with_new("powershell.exe", |command| { + let mut child = CommandWrap::with_new("powershell.exe", |command| { command.arg("/C").arg("echo hello").stdout(Stdio::null()); }) .spawn()?; @@ -18,7 +18,7 @@ async fn nowrap() -> Result<()> { #[tokio::test] async fn job_object() -> Result<()> { - let mut child = TokioCommandWrap::with_new("powershell.exe", |command| { + let mut child = CommandWrap::with_new("powershell.exe", |command| { command.arg("/C").arg("echo hello").stdout(Stdio::null()); }) .wrap(JobObject) diff --git a/tests/tokio_windows/wait_with_output.rs b/tests/tokio_windows/wait_with_output.rs index d7963a6..cd8b345 100644 --- a/tests/tokio_windows/wait_with_output.rs +++ b/tests/tokio_windows/wait_with_output.rs @@ -2,7 +2,7 @@ use super::prelude::*; #[tokio::test] async fn nowrap() -> Result<()> { - let child = TokioCommandWrap::with_new("powershell.exe", |command| { + let child = CommandWrap::with_new("powershell.exe", |command| { command.arg("/C").arg("echo hello").stdout(Stdio::piped()); }) .spawn()?; @@ -16,7 +16,7 @@ async fn nowrap() -> Result<()> { #[tokio::test] async fn job_object() -> Result<()> { - let child = TokioCommandWrap::with_new("powershell.exe", |command| { + let child = CommandWrap::with_new("powershell.exe", |command| { command.arg("/C").arg("echo hello").stdout(Stdio::piped()); }) .wrap(JobObject) From 2fa74d500f6d2fa4dfe60711020cc935bf7eb374 Mon Sep 17 00:00:00 2001 From: Brooks J Rady Date: Tue, 22 Jul 2025 18:20:15 +0100 Subject: [PATCH 20/21] style(clippy): convert tabs to spaces in doctests --- src/lib.rs | 334 ++++++++++++++++++++++++++--------------------------- 1 file changed, 167 insertions(+), 167 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 79d81b6..ed80d14 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -161,27 +161,27 @@ //! # use std::{fs::File, io, path::PathBuf, process::Command, thread}; //! #[derive(Debug)] //! struct LogFile { -//! path: PathBuf, +//! path: PathBuf, //! } //! //! impl LogFile { -//! fn new(path: impl Into) -> Self { -//! Self { path: path.into() } -//! } +//! fn new(path: impl Into) -> Self { +//! Self { path: path.into() } +//! } //! } //! //! impl CommandWrapper for LogFile { -//! fn pre_spawn(&mut self, command: &mut Command, _core: &CommandWrap) -> io::Result<()> { -//! let mut logfile = File::create(&self.path)?; -//! let (mut rx, tx) = io::pipe()?; +//! fn pre_spawn(&mut self, command: &mut Command, _core: &CommandWrap) -> io::Result<()> { +//! let mut logfile = File::create(&self.path)?; +//! let (mut rx, tx) = io::pipe()?; //! -//! thread::spawn(move || { -//! io::copy(&mut rx, &mut logfile).unwrap(); -//! }); +//! thread::spawn(move || { +//! io::copy(&mut rx, &mut logfile).unwrap(); +//! }); //! -//! command.stdout(tx.try_clone()?).stderr(tx); -//! Ok(()) -//! } +//! command.stdout(tx.try_clone()?).stderr(tx); +//! Ok(()) +//! } //! } //! ``` //! @@ -194,81 +194,81 @@ //! ```rust //! # use process_wrap::std::{ChildWrapper, CommandWrap, CommandWrapper}; //! # use std::{ -//! # fs::File, -//! # io, mem, -//! # path::PathBuf, -//! # process::{Command, ExitStatus}, -//! # thread::{self, JoinHandle}, +//! # fs::File, +//! # io, mem, +//! # path::PathBuf, +//! # process::{Command, ExitStatus}, +//! # thread::{self, JoinHandle}, //! # }; //! #[derive(Debug)] //! struct LogFile { -//! path: PathBuf, -//! thread: Option>, +//! path: PathBuf, +//! thread: Option>, //! } //! //! impl LogFile { -//! fn new(path: impl Into) -> Self { -//! Self { -//! path: path.into(), -//! thread: None, -//! } -//! } +//! fn new(path: impl Into) -> Self { +//! Self { +//! path: path.into(), +//! thread: None, +//! } +//! } //! } //! //! impl CommandWrapper for LogFile { -//! fn pre_spawn(&mut self, command: &mut Command, _core: &CommandWrap) -> io::Result<()> { -//! let mut logfile = File::create(&self.path)?; -//! let (mut rx, tx) = io::pipe()?; -//! -//! self.thread = Some(thread::spawn(move || { -//! io::copy(&mut rx, &mut logfile).unwrap(); -//! })); -//! -//! command.stdout(tx.try_clone()?).stderr(tx); -//! Ok(()) -//! } -//! -//! fn wrap_child( -//! &mut self, -//! child: Box, -//! _core: &CommandWrap, -//! ) -> io::Result> { -//! let wrapped_child = LogFileChild { -//! inner: child, -//! thread: mem::take(&mut self.thread), -//! }; -//! Ok(Box::new(wrapped_child)) -//! } +//! fn pre_spawn(&mut self, command: &mut Command, _core: &CommandWrap) -> io::Result<()> { +//! let mut logfile = File::create(&self.path)?; +//! let (mut rx, tx) = io::pipe()?; +//! +//! self.thread = Some(thread::spawn(move || { +//! io::copy(&mut rx, &mut logfile).unwrap(); +//! })); +//! +//! command.stdout(tx.try_clone()?).stderr(tx); +//! Ok(()) +//! } +//! +//! fn wrap_child( +//! &mut self, +//! child: Box, +//! _core: &CommandWrap, +//! ) -> io::Result> { +//! let wrapped_child = LogFileChild { +//! inner: child, +//! thread: mem::take(&mut self.thread), +//! }; +//! Ok(Box::new(wrapped_child)) +//! } //! } //! //! #[derive(Debug)] //! struct LogFileChild { -//! inner: Box, -//! thread: Option>, +//! inner: Box, +//! thread: Option>, //! } //! //! impl ChildWrapper for LogFileChild { -//! fn inner(&self) -> &dyn ChildWrapper { -//! &*self.inner -//! } +//! fn inner(&self) -> &dyn ChildWrapper { +//! &*self.inner +//! } //! -//! fn inner_mut(&mut self) -> &mut dyn ChildWrapper { -//! &mut *self.inner -//! } +//! fn inner_mut(&mut self) -> &mut dyn ChildWrapper { +//! &mut *self.inner +//! } //! -//! fn into_inner(self: Box) -> Box { -//! self.inner -//! } +//! fn into_inner(self: Box) -> Box { +//! self.inner +//! } //! -//! fn wait(&mut self) -> io::Result { -//! let exit_status = self.inner.wait(); +//! fn wait(&mut self) -> io::Result { +//! let exit_status = self.inner.wait(); //! -//! if let Some(thread) = mem::take(&mut self.thread) { -//! thread.join().unwrap(); -//! } +//! if let Some(thread) = mem::take(&mut self.thread) { +//! thread.join().unwrap(); +//! } //! -//! exit_status -//! } +//! exit_status +//! } //! } //! ``` //! @@ -285,30 +285,30 @@ //! ```rust //! # use process_wrap::std::{CommandWrap, CommandWrapper}; //! # use std::{ -//! # io, -//! # path::PathBuf, -//! # process::{Child, Command, Stdio}, -//! # thread::JoinHandle, +//! # io, +//! # path::PathBuf, +//! # process::{Child, Command, Stdio}, +//! # thread::JoinHandle, //! # }; //! # #[derive(Debug)] //! # struct LogFile { -//! # path: PathBuf, -//! # thread: Option>, +//! # path: PathBuf, +//! # thread: Option>, //! # } //! # //! impl CommandWrapper for LogFile { -//! // ... snip ... -//! fn post_spawn( -//! &mut self, -//! command: &mut Command, -//! _child: &mut Child, -//! _core: &CommandWrap, -//! ) -> io::Result<()> { -//! command.stdout(Stdio::null()).stderr(Stdio::null()); -//! -//! Ok(()) -//! } -//! // ... snip ... +//! // ... snip ... +//! fn post_spawn( +//! &mut self, +//! command: &mut Command, +//! _child: &mut Child, +//! _core: &CommandWrap, +//! ) -> io::Result<()> { +//! command.stdout(Stdio::null()).stderr(Stdio::null()); +//! +//! Ok(()) +//! } +//! // ... snip ... //! } //! ``` //! @@ -317,118 +317,118 @@ //! ```rust //! # use process_wrap::std::{ChildWrapper, CommandWrap, CommandWrapper}; //! # use std::{ -//! # error::Error, -//! # fs::{self, File}, -//! # io, mem, -//! # path::PathBuf, -//! # process::{Child, Command, ExitStatus, Stdio}, -//! # thread::{self, JoinHandle}, +//! # error::Error, +//! # fs::{self, File}, +//! # io, mem, +//! # path::PathBuf, +//! # process::{Child, Command, ExitStatus, Stdio}, +//! # thread::{self, JoinHandle}, //! # }; //! # use tempfile::NamedTempFile; //! # #[derive(Debug)] //! # struct LogFile { -//! # path: PathBuf, -//! # thread: Option>, +//! # path: PathBuf, +//! # thread: Option>, //! # } //! # //! # impl LogFile { -//! # fn new(path: impl Into) -> Self { -//! # Self { -//! # path: path.into(), -//! # thread: None, -//! # } -//! # } +//! # fn new(path: impl Into) -> Self { +//! # Self { +//! # path: path.into(), +//! # thread: None, +//! # } +//! # } //! # } //! # //! # impl CommandWrapper for LogFile { -//! # fn pre_spawn(&mut self, command: &mut Command, _core: &CommandWrap) -> io::Result<()> { -//! # let mut logfile = File::create(&self.path)?; -//! # let (mut rx, tx) = io::pipe()?; +//! # fn pre_spawn(&mut self, command: &mut Command, _core: &CommandWrap) -> io::Result<()> { +//! # let mut logfile = File::create(&self.path)?; +//! # let (mut rx, tx) = io::pipe()?; //! # -//! # self.thread = Some(thread::spawn(move || { -//! # io::copy(&mut rx, &mut logfile).unwrap(); -//! # })); +//! # self.thread = Some(thread::spawn(move || { +//! # io::copy(&mut rx, &mut logfile).unwrap(); +//! # })); //! # -//! # command.stdout(tx.try_clone()?).stderr(tx); -//! # Ok(()) -//! # } +//! # command.stdout(tx.try_clone()?).stderr(tx); +//! # Ok(()) +//! # } //! # -//! # fn post_spawn( -//! # &mut self, -//! # command: &mut Command, -//! # _child: &mut Child, -//! # _core: &CommandWrap, -//! # ) -> io::Result<()> { -//! # command.stdout(Stdio::null()).stderr(Stdio::null()); +//! # fn post_spawn( +//! # &mut self, +//! # command: &mut Command, +//! # _child: &mut Child, +//! # _core: &CommandWrap, +//! # ) -> io::Result<()> { +//! # command.stdout(Stdio::null()).stderr(Stdio::null()); //! # -//! # Ok(()) -//! # } +//! # Ok(()) +//! # } //! # -//! # fn wrap_child( -//! # &mut self, -//! # child: Box, -//! # _core: &CommandWrap, -//! # ) -> io::Result> { -//! # let wrapped_child = LogFileChild { -//! # inner: child, -//! # thread: mem::take(&mut self.thread), -//! # }; -//! # Ok(Box::new(wrapped_child)) -//! # } +//! # fn wrap_child( +//! # &mut self, +//! # child: Box, +//! # _core: &CommandWrap, +//! # ) -> io::Result> { +//! # let wrapped_child = LogFileChild { +//! # inner: child, +//! # thread: mem::take(&mut self.thread), +//! # }; +//! # Ok(Box::new(wrapped_child)) +//! # } //! # } //! # //! # #[derive(Debug)] //! # struct LogFileChild { -//! # inner: Box, -//! # thread: Option>, +//! # inner: Box, +//! # thread: Option>, //! # } //! # //! # impl ChildWrapper for LogFileChild { -//! # fn inner(&self) -> &dyn ChildWrapper { -//! # &*self.inner -//! # } +//! # fn inner(&self) -> &dyn ChildWrapper { +//! # &*self.inner +//! # } //! # -//! # fn inner_mut(&mut self) -> &mut dyn ChildWrapper { -//! # &mut *self.inner -//! # } +//! # fn inner_mut(&mut self) -> &mut dyn ChildWrapper { +//! # &mut *self.inner +//! # } //! # -//! # fn into_inner(self: Box) -> Box { -//! # self.inner -//! # } +//! # fn into_inner(self: Box) -> Box { +//! # self.inner +//! # } //! # -//! # fn wait(&mut self) -> io::Result { -//! # let exit_status = self.inner.wait(); +//! # fn wait(&mut self) -> io::Result { +//! # let exit_status = self.inner.wait(); //! # -//! # if let Some(thread) = mem::take(&mut self.thread) { -//! # thread.join().unwrap(); -//! # } +//! # if let Some(thread) = mem::take(&mut self.thread) { +//! # thread.join().unwrap(); +//! # } //! # -//! # exit_status -//! # } +//! # exit_status +//! # } //! # } //! # //! fn main() -> Result<(), Box> { -//! #[cfg(windows)] -//! let mut command = CommandWrap::with_new("cmd", |command| { -//! command.args(["/c", "echo Hello && echo World 1>&2"]); -//! }); -//! #[cfg(unix)] -//! let mut command = CommandWrap::with_new("sh", |command| { -//! command.args(["-c", "echo Hello && echo World 1>&2"]); -//! }); -//! -//! let logfile = NamedTempFile::new()?; -//! let logfile_path = logfile.path(); -//! -//! command.wrap(LogFile::new(logfile_path)).spawn()?.wait()?; -//! -//! let logfile_lines: Vec = fs::read_to_string(logfile_path)? -//! .lines() -//! .map(|l| l.trim().into()) -//! .collect(); -//! assert_eq!(logfile_lines, vec!["Hello", "World"]); -//! -//! Ok(()) +//! #[cfg(windows)] +//! let mut command = CommandWrap::with_new("cmd", |command| { +//! command.args(["/c", "echo Hello && echo World 1>&2"]); +//! }); +//! #[cfg(unix)] +//! let mut command = CommandWrap::with_new("sh", |command| { +//! command.args(["-c", "echo Hello && echo World 1>&2"]); +//! }); +//! +//! let logfile = NamedTempFile::new()?; +//! let logfile_path = logfile.path(); +//! +//! command.wrap(LogFile::new(logfile_path)).spawn()?.wait()?; +//! +//! let logfile_lines: Vec = fs::read_to_string(logfile_path)? +//! .lines() +//! .map(|l| l.trim().into()) +//! .collect(); +//! assert_eq!(logfile_lines, vec!["Hello", "World"]); +//! +//! Ok(()) //! } //! ``` //! From a7cff0a0bd2b8f5125d796514f953c235a4d018a Mon Sep 17 00:00:00 2001 From: Brooks J Rady Date: Wed, 23 Jul 2025 10:50:46 +0100 Subject: [PATCH 21/21] test(windows): fix failing Windows tests --- src/std/creation_flags.rs | 4 ++-- src/std/job_object.rs | 24 ++++++++++++------------ src/tokio/creation_flags.rs | 4 ++-- src/tokio/job_object.rs | 24 ++++++++++++------------ 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/std/creation_flags.rs b/src/std/creation_flags.rs index 5be7f6b..00c08c5 100644 --- a/src/std/creation_flags.rs +++ b/src/std/creation_flags.rs @@ -18,8 +18,8 @@ use super::{CommandWrap, CommandWrapper}; #[derive(Clone, Copy, Debug)] pub struct CreationFlags(pub PROCESS_CREATION_FLAGS); -impl StdCommandWrapper for CreationFlags { - fn pre_spawn(&mut self, command: &mut Command, _core: &StdCommandWrap) -> Result<()> { +impl CommandWrapper for CreationFlags { + fn pre_spawn(&mut self, command: &mut Command, _core: &CommandWrap) -> Result<()> { command.creation_flags((self.0).0); Ok(()) } diff --git a/src/std/job_object.rs b/src/std/job_object.rs index a997ef3..586b624 100644 --- a/src/std/job_object.rs +++ b/src/std/job_object.rs @@ -19,7 +19,7 @@ use crate::{ #[cfg(feature = "creation-flags")] use super::CreationFlags; -use super::{StdChildWrapper, CommandWrap, CommandWrapper}; +use super::{ChildWrapper, CommandWrap, CommandWrapper}; /// Wrapper which creates a job object context for a `Command`. /// @@ -37,9 +37,9 @@ use super::{StdChildWrapper, CommandWrap, CommandWrapper}; #[derive(Clone, Copy, Debug)] pub struct JobObject; -impl StdCommandWrapper for JobObject { +impl CommandWrapper for JobObject { #[cfg_attr(feature = "tracing", instrument(level = "debug", skip(self)))] - fn pre_spawn(&mut self, command: &mut Command, core: &StdCommandWrap) -> Result<()> { + fn pre_spawn(&mut self, command: &mut Command, core: &CommandWrap) -> Result<()> { let mut flags = CREATE_SUSPENDED; #[cfg(feature = "creation-flags")] if let Some(CreationFlags(user_flags)) = core.get_wrap::() { @@ -53,9 +53,9 @@ impl StdCommandWrapper for JobObject { #[cfg_attr(feature = "tracing", instrument(level = "debug", skip(self)))] fn wrap_child( &mut self, - inner: Box, - core: &StdCommandWrap, - ) -> Result> { + inner: Box, + core: &CommandWrap, + ) -> Result> { #[cfg(feature = "creation-flags")] let create_suspended = core .get_wrap::() @@ -82,14 +82,14 @@ impl StdCommandWrapper for JobObject { /// Wrapper for `Child` which waits on all processes within the job. #[derive(Debug)] pub struct JobObjectChild { - inner: Box, + inner: Box, exit_status: ChildExitStatus, job_port: JobPort, } impl JobObjectChild { #[cfg_attr(feature = "tracing", instrument(level = "debug", skip(job_port)))] - pub(crate) fn new(inner: Box, job_port: JobPort) -> Self { + pub(crate) fn new(inner: Box, job_port: JobPort) -> Self { Self { inner, exit_status: ChildExitStatus::Running, @@ -98,14 +98,14 @@ impl JobObjectChild { } } -impl StdChildWrapper for JobObjectChild { - fn inner(&self) -> &dyn StdChildWrapper { +impl ChildWrapper for JobObjectChild { + fn inner(&self) -> &dyn ChildWrapper { self.inner.inner() } - fn inner_mut(&mut self) -> &mut dyn StdChildWrapper { + fn inner_mut(&mut self) -> &mut dyn ChildWrapper { self.inner.inner_mut() } - fn into_inner(self: Box) -> Box { + fn into_inner(self: Box) -> Box { // manually drop the completion port let its = std::mem::ManuallyDrop::new(self.job_port); unsafe { CloseHandle(its.completion_port.0) }.ok(); diff --git a/src/tokio/creation_flags.rs b/src/tokio/creation_flags.rs index f204b8a..58e1575 100644 --- a/src/tokio/creation_flags.rs +++ b/src/tokio/creation_flags.rs @@ -19,8 +19,8 @@ use super::{CommandWrap, CommandWrapper}; #[derive(Clone, Copy, Debug)] pub struct CreationFlags(pub PROCESS_CREATION_FLAGS); -impl TokioCommandWrapper for CreationFlags { - fn pre_spawn(&mut self, command: &mut Command, _core: &TokioCommandWrap) -> Result<()> { +impl CommandWrapper for CreationFlags { + fn pre_spawn(&mut self, command: &mut Command, _core: &CommandWrap) -> Result<()> { command.creation_flags((self.0).0); Ok(()) } diff --git a/src/tokio/job_object.rs b/src/tokio/job_object.rs index fadd970..ce33feb 100644 --- a/src/tokio/job_object.rs +++ b/src/tokio/job_object.rs @@ -17,7 +17,7 @@ use crate::{ use super::CreationFlags; #[cfg(feature = "kill-on-drop")] use super::KillOnDrop; -use super::{TokioChildWrapper, CommandWrap, CommandWrapper}; +use super::{ChildWrapper, CommandWrap, CommandWrapper}; /// Wrapper which creates a job object context for a `Command`. /// @@ -35,9 +35,9 @@ use super::{TokioChildWrapper, CommandWrap, CommandWrapper}; #[derive(Clone, Copy, Debug)] pub struct JobObject; -impl TokioCommandWrapper for JobObject { +impl CommandWrapper for JobObject { #[cfg_attr(feature = "tracing", instrument(level = "debug", skip(self)))] - fn pre_spawn(&mut self, command: &mut Command, core: &TokioCommandWrap) -> Result<()> { + fn pre_spawn(&mut self, command: &mut Command, core: &CommandWrap) -> Result<()> { let mut flags = CREATE_SUSPENDED; #[cfg(feature = "creation-flags")] if let Some(CreationFlags(user_flags)) = core.get_wrap::() { @@ -51,9 +51,9 @@ impl TokioCommandWrapper for JobObject { #[cfg_attr(feature = "tracing", instrument(level = "debug", skip(self)))] fn wrap_child( &mut self, - inner: Box, - core: &TokioCommandWrap, - ) -> Result> { + inner: Box, + core: &CommandWrap, + ) -> Result> { #[cfg(feature = "kill-on-drop")] let kill_on_drop = core.has_wrap::(); #[cfg(not(feature = "kill-on-drop"))] @@ -94,14 +94,14 @@ impl TokioCommandWrapper for JobObject { /// Wrapper for `Child` which waits on all processes within the job. #[derive(Debug)] pub struct JobObjectChild { - inner: Box, + inner: Box, exit_status: ChildExitStatus, job_port: JobPort, } impl JobObjectChild { #[cfg_attr(feature = "tracing", instrument(level = "debug", skip(job_port)))] - pub(crate) fn new(inner: Box, job_port: JobPort) -> Self { + pub(crate) fn new(inner: Box, job_port: JobPort) -> Self { Self { inner, exit_status: ChildExitStatus::Running, @@ -110,14 +110,14 @@ impl JobObjectChild { } } -impl TokioChildWrapper for JobObjectChild { - fn inner(&self) -> &dyn TokioChildWrapper { +impl ChildWrapper for JobObjectChild { + fn inner(&self) -> &dyn ChildWrapper { self.inner.inner() } - fn inner_mut(&mut self) -> &mut dyn TokioChildWrapper { + fn inner_mut(&mut self) -> &mut dyn ChildWrapper { self.inner.inner_mut() } - fn into_inner(self: Box) -> Box { + fn into_inner(self: Box) -> Box { // manually drop the completion port let its = std::mem::ManuallyDrop::new(self.job_port); unsafe { CloseHandle(its.completion_port.0) }.ok();