1- use std:: {
2- io,
3- ops:: { Deref , DerefMut } ,
4- process:: { Child , Command } ,
5- } ;
1+ use std:: { io, process:: Child } ;
62
7- use crate :: { Interruptible , InterruptibleCommand } ;
3+ use crate :: Interruptible ;
84
9- #[ cfg( windows) ]
10- fn set_creation_flags ( command : & mut Command ) {
11- use std:: os:: windows:: process:: CommandExt as _;
12- command. creation_flags ( crate :: CREATE_NEW_PROCESS_GROUP ) ;
13- }
14-
15- impl InterruptibleCommand for Command {
16- type Child = InterruptibleChild ;
17-
18- fn spawn_interruptible ( & mut self ) -> io:: Result < InterruptibleChild > {
19- #[ cfg( windows) ]
20- set_creation_flags ( self ) ;
21- self . spawn ( ) . map ( InterruptibleChild )
22- }
23- }
24-
25- /// A child process that can be interrupted
26- pub struct InterruptibleChild ( Child ) ;
27-
28- impl Interruptible for InterruptibleChild {
5+ impl Interruptible for Child {
296 fn pid ( & mut self ) -> io:: Result < Option < u32 > > {
30- match self . 0 . try_wait ( ) {
7+ match self . try_wait ( ) {
318 Ok ( Some ( _) ) => Ok ( None ) ,
32- Ok ( None ) => Ok ( Some ( self . 0 . id ( ) ) ) ,
9+ Ok ( None ) => Ok ( Some ( self . id ( ) ) ) ,
3310 Err ( e) => Err ( e) ,
3411 }
3512 }
3613}
3714
38- impl Deref for InterruptibleChild {
39- type Target = Child ;
40-
41- fn deref ( & self ) -> & Self :: Target {
42- & self . 0
43- }
44- }
45-
46- impl DerefMut for InterruptibleChild {
47- fn deref_mut ( & mut self ) -> & mut Self :: Target {
48- & mut self . 0
49- }
50- }
51-
5215#[ cfg( test) ]
5316mod tests {
5417 use super :: * ;
@@ -60,7 +23,7 @@ mod tests {
6023 command. arg ( "-t" ) ;
6124 command. arg ( "127.0.0.1" ) ;
6225
63- let mut child = command. spawn_interruptible ( ) . unwrap ( ) ;
26+ let mut child = command. spawn ( ) . unwrap ( ) ;
6427 child. interrupt ( ) . unwrap ( ) ;
6528 child. wait ( ) . unwrap ( ) ;
6629 }
@@ -69,7 +32,7 @@ mod tests {
6932 fn test_completed_interruptible_command ( ) {
7033 let mut command = std:: process:: Command :: new ( "ping" ) ;
7134
72- let mut child = command. spawn_interruptible ( ) . unwrap ( ) ;
35+ let mut child = command. spawn ( ) . unwrap ( ) ;
7336 child. wait ( ) . unwrap ( ) ;
7437 assert ! ( child. interrupt( ) . is_err( ) ) ;
7538 }
0 commit comments