Implement Error for ExitCode

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
Matthias Beyer 2019-10-19 08:41:17 +02:00
parent e3db947e68
commit 19f6391d8a

View file

@ -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;
}