Implement Error for ExitCode
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
parent
e3db947e68
commit
19f6391d8a
1 changed files with 24 additions and 0 deletions
|
@ -17,6 +17,10 @@
|
|||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
//
|
||||
|
||||
use std::error::Error;
|
||||
use std::fmt::{Formatter, Display};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ExitCode(i32);
|
||||
|
||||
impl From<i32> for ExitCode {
|
||||
|
@ -31,6 +35,26 @@ impl ExitCode {
|
|||
}
|
||||
}
|
||||
|
||||
impl Display for ExitCode {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> {
|
||||
write!(f, "ExitCode {}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Error for ExitCode {
|
||||
fn description(&self) -> &str {
|
||||
"ExitCode"
|
||||
}
|
||||
|
||||
fn cause(&self) -> Option<&dyn Error> {
|
||||
None
|
||||
}
|
||||
|
||||
fn source(&self) -> Option<&(dyn Error + 'static)> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ExitUnwrap<T> {
|
||||
fn unwrap_or_exit(self) -> T;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue