Skip to main content

devela/work/exec/process/
error.rs

1// devela/src/work/exec/process/error.rs
2//
3//! Defines [`ExitStatusError`].
4//
5
6use crate::{ExitStatus, impl_trait};
7
8#[doc = crate::_tags!(platform runtime error)]
9/// Indicates that a process terminated unsuccessfully.
10#[doc = crate::_doc_meta!{location("work/process")}]
11/// This type is a stable placeholder for the unstable standard library's
12/// [`ExitStatusError`](https://doc.rust-lang.org/std/process/struct.ExitStatusError.html)
13// WAIT: [ExitStatusError](https://github.com/rust-lang/rust/issues/84908)
14#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
15pub struct ExitStatusError {
16    pub(crate) status: ExitStatus,
17}
18
19impl_trait!(fmt::Display+Error for ExitStatusError |self, f| {
20    write!(f, "process exited unsuccessfully: {}", self.status)
21});
22
23impl ExitStatusError {
24    /// Reports the exit code, if applicable, from an ExitStatusError.
25    pub fn code(&self) -> Option<i32> {
26        self.status.code()
27    }
28
29    /// Converts an `ExitStatusError` (back) to an `ExitStatus`.
30    pub const fn into_status(&self) -> ExitStatus {
31        self.status
32    }
33}