@@ -171,21 +171,21 @@ impl Command {
171
171
}
172
172
173
173
/// Configuration for the child process’s standard input (stdin) handle.
174
- pub fn stdin ( & mut self , cfg : impl Into < process :: Stdio > ) -> & mut Self {
175
- self . 0 . stdin ( cfg) ;
176
- self
174
+ pub fn stdin < S : TryInto < process :: Stdio > > ( & mut self , cfg : S ) -> Result < & mut Self , S :: Error > {
175
+ self . 0 . stdin ( cfg. try_into ( ) ? ) ;
176
+ Ok ( self )
177
177
}
178
178
179
179
/// Configuration for the child process’s standard output (stdout) handle.
180
- pub fn stdout ( & mut self , cfg : impl Into < process :: Stdio > ) -> & mut Self {
181
- self . 0 . stdout ( cfg) ;
182
- self
180
+ pub fn stdout < S : TryInto < process :: Stdio > > ( & mut self , cfg : S ) -> Result < & mut Self , S :: Error > {
181
+ self . 0 . stdout ( cfg. try_into ( ) ? ) ;
182
+ Ok ( self )
183
183
}
184
184
185
185
/// Configuration for the child process’s standard error (stderr) handle.
186
- pub fn stderr ( & mut self , cfg : impl Into < process :: Stdio > ) -> & mut Self {
187
- self . 0 . stderr ( cfg) ;
188
- self
186
+ pub fn stderr < S : TryInto < process :: Stdio > > ( & mut self , cfg : S ) -> Result < & mut Self , S :: Error > {
187
+ self . 0 . stderr ( cfg. try_into ( ) ? ) ;
188
+ Ok ( self )
189
189
}
190
190
191
191
/// Returns the path to the program.
@@ -409,15 +409,16 @@ impl ChildStdout {
409
409
}
410
410
}
411
411
412
- impl From < ChildStdout > for process:: Stdio {
413
- fn from ( value : ChildStdout ) -> Self {
414
- Self :: from (
415
- value
416
- . 0
417
- . into_inner ( )
418
- . try_unwrap ( )
419
- . expect ( "the handle is being used" ) ,
420
- )
412
+ impl TryFrom < ChildStdout > for process:: Stdio {
413
+ type Error = ChildStdout ;
414
+
415
+ fn try_from ( value : ChildStdout ) -> Result < Self , ChildStdout > {
416
+ value
417
+ . 0
418
+ . into_inner ( )
419
+ . try_unwrap ( )
420
+ . map ( Self :: from)
421
+ . map_err ( |fd| ChildStdout ( unsafe { Attacher :: from_shared_fd_unchecked ( fd) } ) )
421
422
}
422
423
}
423
424
@@ -430,15 +431,16 @@ impl ChildStderr {
430
431
}
431
432
}
432
433
433
- impl From < ChildStderr > for process:: Stdio {
434
- fn from ( value : ChildStderr ) -> Self {
435
- Self :: from (
436
- value
437
- . 0
438
- . into_inner ( )
439
- . try_unwrap ( )
440
- . expect ( "the handle is being used" ) ,
441
- )
434
+ impl TryFrom < ChildStderr > for process:: Stdio {
435
+ type Error = ChildStderr ;
436
+
437
+ fn try_from ( value : ChildStderr ) -> Result < Self , ChildStderr > {
438
+ value
439
+ . 0
440
+ . into_inner ( )
441
+ . try_unwrap ( )
442
+ . map ( Self :: from)
443
+ . map_err ( |fd| ChildStderr ( unsafe { Attacher :: from_shared_fd_unchecked ( fd) } ) )
442
444
}
443
445
}
444
446
@@ -452,14 +454,15 @@ impl ChildStdin {
452
454
}
453
455
}
454
456
455
- impl From < ChildStdin > for process:: Stdio {
456
- fn from ( value : ChildStdin ) -> Self {
457
- Self :: from (
458
- value
459
- . 0
460
- . into_inner ( )
461
- . try_unwrap ( )
462
- . expect ( "the handle is being used" ) ,
463
- )
457
+ impl TryFrom < ChildStdin > for process:: Stdio {
458
+ type Error = ChildStdin ;
459
+
460
+ fn try_from ( value : ChildStdin ) -> Result < Self , ChildStdin > {
461
+ value
462
+ . 0
463
+ . into_inner ( )
464
+ . try_unwrap ( )
465
+ . map ( Self :: from)
466
+ . map_err ( |fd| ChildStdin ( unsafe { Attacher :: from_shared_fd_unchecked ( fd) } ) )
464
467
}
465
468
}
0 commit comments