Suggestion: Add ExitCodeExt for Windows · Issue #97914 · rust-lang/rust (original) (raw)

I welcome the newly stabilized ExitCode which allows Termination with an exit code.

I am facing some difficulties using it on Windows however, most programs on Windows if they use the exit code at all return an HRESULT or DWORD, neither of which are constructible from the current only available impl From<u8> for ExitCode. Right now I resort to using pointers to access the internals of ExitCode on Windows, which is undesirable. I suggest adding the following windows-specific trait:

impl From for ExitCode { fn from(code: i32) -> Self { ... } }

Alternatively, a trait named ExitCodeExt could also be added for Windows which allows generation of i32 based error codes.