@@ -5,13 +5,15 @@ mod tests;
5
5
6
6
use crate :: cmp;
7
7
use crate :: collections:: BTreeMap ;
8
+ use crate :: convert:: Infallible ;
8
9
use crate :: env;
9
10
use crate :: env:: consts:: { EXE_EXTENSION , EXE_SUFFIX } ;
10
11
use crate :: ffi:: { OsStr , OsString } ;
11
12
use crate :: fmt;
12
13
use crate :: io:: { self , Error , ErrorKind } ;
13
14
use crate :: mem;
14
15
use crate :: num:: NonZeroI32 ;
16
+ use crate :: ops:: ControlFlow ;
15
17
use crate :: os:: windows:: ffi:: { OsStrExt , OsStringExt } ;
16
18
use crate :: os:: windows:: io:: { AsHandle , AsRawHandle , BorrowedHandle , FromRawHandle , IntoRawHandle } ;
17
19
use crate :: path:: { Path , PathBuf } ;
@@ -675,6 +677,21 @@ impl ExitStatus {
675
677
pub fn code ( & self ) -> Option < i32 > {
676
678
Some ( self . 0 as i32 )
677
679
}
680
+
681
+ pub fn try_branch (
682
+ self ,
683
+ ) -> ControlFlow < Result < Infallible , crate :: process:: ExitStatusError > , ( ) > {
684
+ match NonZeroDWORD :: try_from ( self . 0 ) {
685
+ Ok ( failure) => ControlFlow :: Break ( Err ( crate :: process:: ExitStatusError :: new (
686
+ ExitStatusError ( failure) ,
687
+ ) ) ) ,
688
+ Err ( _) => ControlFlow :: Continue ( ( ) ) ,
689
+ }
690
+ }
691
+
692
+ pub fn zero_status ( ) -> ExitStatus {
693
+ ExitStatus ( 0 )
694
+ }
678
695
}
679
696
680
697
/// Converts a raw `c::DWORD` to a type-safe `ExitStatus` by wrapping it without copying.
0 commit comments