unix: impl ExitStatusExt for ExitStatusError
It is unergnomic to have to say things like bad.into_status().signal() Implementing `ExitStatusExt` for `ExitStatusError` fixes this. Unfortunately it does mean making a previously-infallible method capable of panicing, although of course the existing impl remains infallible. The alternative would be a whole new `ExitStatusErrorExt` trait. `<ExitStatus as ExitStatusExt>::into_raw()` is not particularly ergonomic to call because of the often-required type annotation. See for example the code in the test case in library/std/src/sys/unix/process/process_unix/tests.rs Perhaps we should provide equivalent free functions for `ExitStatus` and `ExitStatusExt` in std::os::unix::process and maybe deprecate this trait method. But I think that is for the future. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
This commit is contained in:
parent
e893089ea0
commit
60a4d9612d
2 changed files with 76 additions and 10 deletions
|
@ -1500,6 +1500,10 @@ impl fmt::Display for ExitStatus {
|
|||
}
|
||||
}
|
||||
|
||||
/// Allows extension traits within `std`.
|
||||
#[unstable(feature = "sealed", issue = "none")]
|
||||
impl crate::sealed::Sealed for ExitStatusError {}
|
||||
|
||||
/// Describes the result of a process after it has failed
|
||||
///
|
||||
/// Produced by the [`.exit_ok`](ExitStatus::exit_ok) method on [`ExitStatus`].
|
||||
|
@ -1536,9 +1540,8 @@ impl ExitStatusError {
|
|||
/// runtime system (often, for example, 255, 254, 127 or 126).
|
||||
///
|
||||
/// On Unix, this will return `None` if the process was terminated by a signal. If you want to
|
||||
/// handle such situations specially, consider using
|
||||
/// [`ExitStatusExt`](crate::os::unix::process::ExitStatusExt) (possibly after getting the
|
||||
/// general `ExitStatus` by using [`status()`](ExitStatusError::status).
|
||||
/// handle such situations specially, consider using methods from
|
||||
/// [`ExitStatusExt`](crate::os::unix::process::ExitStatusExt).
|
||||
///
|
||||
/// If the process finished by calling `exit` with a nonzero value, this will return
|
||||
/// that exit status.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue