Skip to content

Commit b7cb1c2

Browse files
committed
Implement ExitCodeExt for Windows
1 parent 48bddb1 commit b7cb1c2

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

std/src/os/windows/process.rs

+19
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,22 @@ impl ChildExt for process::Child {
194194
self.handle.main_thread_handle()
195195
}
196196
}
197+
198+
/// Windows-specific extensions to [`process::ExitCode`].
199+
///
200+
/// This trait is sealed: it cannot be implemented outside the standard library.
201+
/// This is so that future additional methods are not breaking changes.
202+
#[stable(feature = "windows_process_exit_code_from", since = "1.63.0")]
203+
pub trait ExitCodeExt: Sealed {
204+
/// Creates a new `ExitStatus` from the raw underlying `u32` return value of
205+
/// a process.
206+
#[stable(feature = "windows_process_exit_code_from", since = "1.63.0")]
207+
fn from_raw(raw: u32) -> Self;
208+
}
209+
210+
#[stable(feature = "windows_process_exit_code_from", since = "1.63.0")]
211+
impl ExitCodeExt for process::ExitCode {
212+
fn from_raw(raw: u32) -> Self {
213+
process::ExitCode::from_inner(From::from(raw))
214+
}
215+
}

std/src/process.rs

+16
Original file line numberDiff line numberDiff line change
@@ -1708,6 +1708,10 @@ impl crate::error::Error for ExitStatusError {}
17081708
#[stable(feature = "process_exitcode", since = "1.61.0")]
17091709
pub struct ExitCode(imp::ExitCode);
17101710

1711+
/// Allows extension traits within `std`.
1712+
#[unstable(feature = "sealed", issue = "none")]
1713+
impl crate::sealed::Sealed for ExitCode {}
1714+
17111715
#[stable(feature = "process_exitcode", since = "1.61.0")]
17121716
impl ExitCode {
17131717
/// The canonical `ExitCode` for successful termination on this platform.
@@ -1798,6 +1802,18 @@ impl From<u8> for ExitCode {
17981802
}
17991803
}
18001804

1805+
impl AsInner<imp::ExitCode> for ExitCode {
1806+
fn as_inner(&self) -> &imp::ExitCode {
1807+
&self.0
1808+
}
1809+
}
1810+
1811+
impl FromInner<imp::ExitCode> for ExitCode {
1812+
fn from_inner(s: imp::ExitCode) -> ExitCode {
1813+
ExitCode(s)
1814+
}
1815+
}
1816+
18011817
impl Child {
18021818
/// Forces the child process to exit. If the child has already exited, an [`InvalidInput`]
18031819
/// error is returned.

std/src/sys/windows/process.rs

+6
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,12 @@ impl From<u8> for ExitCode {
707707
}
708708
}
709709

710+
impl From<u32> for ExitCode {
711+
fn from(code: u32) -> Self {
712+
ExitCode(c::DWORD::from(code))
713+
}
714+
}
715+
710716
fn zeroed_startupinfo() -> c::STARTUPINFO {
711717
c::STARTUPINFO {
712718
cb: 0,

0 commit comments

Comments
 (0)