Implement ExitCodeExt for Windows
This commit is contained in:
parent
6dc598a01b
commit
0503bc0149
3 changed files with 41 additions and 0 deletions
|
@ -194,3 +194,22 @@ impl ChildExt for process::Child {
|
||||||
self.handle.main_thread_handle()
|
self.handle.main_thread_handle()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Windows-specific extensions to [`process::ExitCode`].
|
||||||
|
///
|
||||||
|
/// This trait is sealed: it cannot be implemented outside the standard library.
|
||||||
|
/// This is so that future additional methods are not breaking changes.
|
||||||
|
#[stable(feature = "windows_process_exit_code_from", since = "1.63.0")]
|
||||||
|
pub trait ExitCodeExt: Sealed {
|
||||||
|
/// Creates a new `ExitStatus` from the raw underlying `u32` return value of
|
||||||
|
/// a process.
|
||||||
|
#[stable(feature = "windows_process_exit_code_from", since = "1.63.0")]
|
||||||
|
fn from_raw(raw: u32) -> Self;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[stable(feature = "windows_process_exit_code_from", since = "1.63.0")]
|
||||||
|
impl ExitCodeExt for process::ExitCode {
|
||||||
|
fn from_raw(raw: u32) -> Self {
|
||||||
|
process::ExitCode::from_inner(From::from(raw))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1708,6 +1708,10 @@ impl crate::error::Error for ExitStatusError {}
|
||||||
#[stable(feature = "process_exitcode", since = "1.61.0")]
|
#[stable(feature = "process_exitcode", since = "1.61.0")]
|
||||||
pub struct ExitCode(imp::ExitCode);
|
pub struct ExitCode(imp::ExitCode);
|
||||||
|
|
||||||
|
/// Allows extension traits within `std`.
|
||||||
|
#[unstable(feature = "sealed", issue = "none")]
|
||||||
|
impl crate::sealed::Sealed for ExitCode {}
|
||||||
|
|
||||||
#[stable(feature = "process_exitcode", since = "1.61.0")]
|
#[stable(feature = "process_exitcode", since = "1.61.0")]
|
||||||
impl ExitCode {
|
impl ExitCode {
|
||||||
/// The canonical `ExitCode` for successful termination on this platform.
|
/// The canonical `ExitCode` for successful termination on this platform.
|
||||||
|
@ -1798,6 +1802,18 @@ impl From<u8> for ExitCode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl AsInner<imp::ExitCode> for ExitCode {
|
||||||
|
fn as_inner(&self) -> &imp::ExitCode {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromInner<imp::ExitCode> for ExitCode {
|
||||||
|
fn from_inner(s: imp::ExitCode) -> ExitCode {
|
||||||
|
ExitCode(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Child {
|
impl Child {
|
||||||
/// Forces the child process to exit. If the child has already exited, an [`InvalidInput`]
|
/// Forces the child process to exit. If the child has already exited, an [`InvalidInput`]
|
||||||
/// error is returned.
|
/// error is returned.
|
||||||
|
|
|
@ -707,6 +707,12 @@ impl From<u8> for ExitCode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<u32> for ExitCode {
|
||||||
|
fn from(code: u32) -> Self {
|
||||||
|
ExitCode(c::DWORD::from(code))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn zeroed_startupinfo() -> c::STARTUPINFO {
|
fn zeroed_startupinfo() -> c::STARTUPINFO {
|
||||||
c::STARTUPINFO {
|
c::STARTUPINFO {
|
||||||
cb: 0,
|
cb: 0,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue