@@ -5,13 +5,15 @@ mod tests;
55
66use crate :: cmp;
77use crate :: collections:: BTreeMap ;
8+ use crate :: convert:: Infallible ;
89use crate :: env;
910use crate :: env:: consts:: { EXE_EXTENSION , EXE_SUFFIX } ;
1011use crate :: ffi:: { OsStr , OsString } ;
1112use crate :: fmt;
1213use crate :: io:: { self , Error , ErrorKind } ;
1314use crate :: mem;
1415use crate :: num:: NonZeroI32 ;
16+ use crate :: ops:: ControlFlow ;
1517use crate :: os:: windows:: ffi:: { OsStrExt , OsStringExt } ;
1618use crate :: os:: windows:: io:: { AsHandle , AsRawHandle , BorrowedHandle , FromRawHandle , IntoRawHandle } ;
1719use crate :: path:: { Path , PathBuf } ;
@@ -675,6 +677,21 @@ impl ExitStatus {
675677 pub fn code ( & self ) -> Option < i32 > {
676678 Some ( self . 0 as i32 )
677679 }
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+ }
678695}
679696
680697/// Converts a raw `c::DWORD` to a type-safe `ExitStatus` by wrapping it without copying.
0 commit comments