@@ -112,10 +112,12 @@ use crate::fmt;
112
112
use crate :: fs;
113
113
use crate :: io:: { self , IoSlice , IoSliceMut } ;
114
114
use crate :: num:: NonZeroI32 ;
115
+ use crate :: ops:: { ControlFlow , FromResidual , Try } ;
115
116
use crate :: path:: Path ;
116
117
use crate :: str;
117
118
use crate :: sys:: pipe:: { read2, AnonPipe } ;
118
119
use crate :: sys:: process as imp;
120
+
119
121
#[ stable( feature = "command_access" , since = "1.57.0" ) ]
120
122
pub use crate :: sys_common:: process:: CommandEnvs ;
121
123
use crate :: sys_common:: { AsInner , AsInnerMut , FromInner , IntoInner } ;
@@ -1542,6 +1544,29 @@ impl fmt::Display for ExitStatus {
1542
1544
}
1543
1545
}
1544
1546
1547
+ #[ unstable( feature = "exit_status_error" , issue = "84908" ) ]
1548
+ impl Try for ExitStatus {
1549
+ type Output = ( ) ;
1550
+ type Residual = Result < Infallible , ExitStatusError > ;
1551
+
1552
+ fn branch ( self ) -> ControlFlow < Self :: Residual , Self :: Output > {
1553
+ self . 0 . try_branch ( )
1554
+ }
1555
+
1556
+ fn from_output ( ( ) : ( ) ) -> Self {
1557
+ Self ( imp:: ExitStatus :: zero_status ( ) )
1558
+ }
1559
+ }
1560
+
1561
+ #[ unstable( feature = "exit_status_error" , issue = "84908" ) ]
1562
+ impl FromResidual < Result < Infallible , ExitStatusError > > for ExitStatus {
1563
+ fn from_residual ( residual : Result < Infallible , ExitStatusError > ) -> Self {
1564
+ match residual {
1565
+ Err ( exit_status_error) => exit_status_error. into ( ) ,
1566
+ }
1567
+ }
1568
+ }
1569
+
1545
1570
/// Allows extension traits within `std`.
1546
1571
#[ unstable( feature = "sealed" , issue = "none" ) ]
1547
1572
impl crate :: sealed:: Sealed for ExitStatusError { }
@@ -1574,6 +1599,9 @@ pub struct ExitStatusError(imp::ExitStatusError);
1574
1599
1575
1600
#[ unstable( feature = "exit_status_error" , issue = "84908" ) ]
1576
1601
impl ExitStatusError {
1602
+ pub ( crate ) fn new ( exit_status_error : imp:: ExitStatusError ) -> Self {
1603
+ ExitStatusError ( exit_status_error)
1604
+ }
1577
1605
/// Reports the exit code, if applicable, from an `ExitStatusError`.
1578
1606
///
1579
1607
/// In Unix terms the return value is the **exit status**: the value passed to `exit`, if the
0 commit comments