Skip to content

Commit f64d808

Browse files
committed
windows implementation of impl Try for ExitStatus.
Signed-off-by: matt rice <[email protected]>
1 parent 94e31c9 commit f64d808

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

library/std/src/sys/windows/process.rs

+17
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ mod tests;
55

66
use crate::cmp;
77
use crate::collections::BTreeMap;
8+
use crate::convert::Infallible;
89
use crate::env;
910
use crate::env::consts::{EXE_EXTENSION, EXE_SUFFIX};
1011
use crate::ffi::{OsStr, OsString};
1112
use crate::fmt;
1213
use crate::io::{self, Error, ErrorKind};
1314
use crate::mem;
1415
use crate::num::NonZeroI32;
16+
use crate::ops::ControlFlow;
1517
use crate::os::windows::ffi::{OsStrExt, OsStringExt};
1618
use crate::os::windows::io::{AsHandle, AsRawHandle, BorrowedHandle, FromRawHandle, IntoRawHandle};
1719
use 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

Comments
 (0)