4
4
) ]
5
5
6
6
macro_rules! Wrap {
7
- ( $name : ident , $ command: ty, $wrapper : ident , $child: ty, $childer: ident, $first_child_wrapper: expr) => {
7
+ ( $command: ty, $child: ty, $childer: ident, $first_child_wrapper: expr) => {
8
8
/// A wrapper around a `Command` that allows for additional functionality to be added.
9
9
///
10
10
/// This is the core type of the `process-wrap` crate. It is a wrapper around a
11
11
#[ doc = concat!( "[`" , stringify!( $command) , "`]." ) ]
12
12
#[ derive( Debug ) ]
13
- pub struct $name {
13
+ pub struct CommandWrap {
14
14
command: $command,
15
- wrappers: :: indexmap:: IndexMap <:: std:: any:: TypeId , Box <dyn $wrapper >>,
15
+ wrappers: :: indexmap:: IndexMap <:: std:: any:: TypeId , Box <dyn CommandWrapper >>,
16
16
}
17
17
18
- impl $name {
18
+ impl CommandWrap {
19
19
/// Create from a program name and a closure to configure the command.
20
20
///
21
21
/// This is a convenience method that creates a new `Command` and then calls the closure
22
22
/// to configure it. The `Command` is then wrapped and returned.
23
23
///
24
- #[ doc = concat!( "Alternatively, use `From`/`Into` to convert a [`" , stringify!( $command) , "`] to a [`" , stringify!( $name ) , "`]." ) ]
24
+ #[ doc = concat!( "Alternatively, use `From`/`Into` to convert a [`" , stringify!( $command) , "`] to a [`" , stringify!( CommandWrap ) , "`]." ) ]
25
25
pub fn with_new(
26
26
program: impl AsRef <:: std:: ffi:: OsStr >,
27
27
init: impl FnOnce ( & mut $command) ,
@@ -60,7 +60,7 @@ macro_rules! Wrap {
60
60
/// will be silently discarded.
61
61
///
62
62
/// Returns `&mut self` for chaining.
63
- pub fn wrap<W : $wrapper + ' static >( & mut self , wrapper: W ) -> & mut Self {
63
+ pub fn wrap<W : CommandWrapper + ' static >( & mut self , wrapper: W ) -> & mut Self {
64
64
let typeid = :: std:: any:: TypeId :: of:: <W >( ) ;
65
65
let mut wrapper = Some ( Box :: new( wrapper) ) ;
66
66
let extant = self
@@ -79,7 +79,7 @@ macro_rules! Wrap {
79
79
fn spawn_inner(
80
80
& self ,
81
81
command: & mut $command,
82
- wrappers: & mut :: indexmap:: IndexMap <:: std:: any:: TypeId , Box <dyn $wrapper >>,
82
+ wrappers: & mut :: indexmap:: IndexMap <:: std:: any:: TypeId , Box <dyn CommandWrapper >>,
83
83
) -> :: std:: io:: Result <Box <dyn $childer>> {
84
84
for ( id, wrapper) in wrappers. iter_mut( ) {
85
85
#[ cfg( feature = "tracing" ) ]
@@ -127,7 +127,7 @@ macro_rules! Wrap {
127
127
}
128
128
129
129
/// Check if a wrapper of a given type is present.
130
- pub fn has_wrap<W : $wrapper + ' static >( & self ) -> bool {
130
+ pub fn has_wrap<W : CommandWrapper + ' static >( & self ) -> bool {
131
131
let typeid = :: std:: any:: TypeId :: of:: <W >( ) ;
132
132
self . wrappers. contains_key( & typeid)
133
133
}
@@ -139,7 +139,7 @@ macro_rules! Wrap {
139
139
///
140
140
/// Returns `None` if the wrapper is not present. To merely check if a wrapper is
141
141
/// present, use `has_wrap` instead.
142
- pub fn get_wrap<W : $wrapper + ' static >( & self ) -> Option <& W > {
142
+ pub fn get_wrap<W : CommandWrapper + ' static >( & self ) -> Option <& W > {
143
143
let typeid = :: std:: any:: TypeId :: of:: <W >( ) ;
144
144
self . wrappers. get( & typeid) . map( |w| {
145
145
let w_any = w as & dyn :: std:: any:: Any ;
@@ -150,7 +150,7 @@ macro_rules! Wrap {
150
150
}
151
151
}
152
152
153
- impl From <Command > for $name {
153
+ impl From <Command > for CommandWrap {
154
154
fn from( command: $command) -> Self {
155
155
Self {
156
156
command,
@@ -169,8 +169,8 @@ macro_rules! Wrap {
169
169
/// ```rust,ignore
170
170
/// #[derive(Debug)]
171
171
/// pub struct YourWrapper;
172
- #[ doc = concat!( "impl " , stringify!( $wrapper ) , " for YourWrapper {}\n ```" ) ]
173
- pub trait $wrapper : :: std:: fmt:: Debug + Send + Sync {
172
+ #[ doc = concat!( "impl " , stringify!( CommandWrapper ) , " for YourWrapper {}\n ```" ) ]
173
+ pub trait CommandWrapper : :: std:: fmt:: Debug + Send + Sync {
174
174
/// Called on a first instance if a second of the same type is added.
175
175
///
176
176
/// Only one of a wrapper type can exist within a Wrap at a time. The default behaviour
@@ -184,7 +184,7 @@ macro_rules! Wrap {
184
184
/// downcasting fails, instead of using unchecked downcasting and unleashing UB.
185
185
///
186
186
/// Default impl: no-op.
187
- fn extend( & mut self , _other: Box <dyn $wrapper >) { }
187
+ fn extend( & mut self , _other: Box <dyn CommandWrapper >) { }
188
188
189
189
/// Called before the command is spawned, to mutate it as needed.
190
190
///
@@ -194,7 +194,7 @@ macro_rules! Wrap {
194
194
/// `CreationFlags` on Windows works along with `JobObject`.
195
195
///
196
196
/// Defaut impl: no-op.
197
- fn pre_spawn( & mut self , _command: & mut $command, _core: & $name ) -> Result <( ) > {
197
+ fn pre_spawn( & mut self , _command: & mut $command, _core: & CommandWrap ) -> Result <( ) > {
198
198
Ok ( ( ) )
199
199
}
200
200
@@ -204,7 +204,7 @@ macro_rules! Wrap {
204
204
/// how `CreationFlags` on Windows works along with `JobObject`.
205
205
///
206
206
/// Default: no-op.
207
- fn post_spawn( & mut self , _command: & mut $command, _child: & mut $child, _core: & $name ) -> Result <( ) > {
207
+ fn post_spawn( & mut self , _command: & mut $command, _child: & mut $child, _core: & CommandWrap ) -> Result <( ) > {
208
208
Ok ( ( ) )
209
209
}
210
210
@@ -222,7 +222,7 @@ macro_rules! Wrap {
222
222
fn wrap_child(
223
223
& mut self ,
224
224
child: Box <dyn $childer>,
225
- _core: & $name ,
225
+ _core: & CommandWrap ,
226
226
) -> Result <Box <dyn $childer>> {
227
227
Ok ( child)
228
228
}
0 commit comments