From 19f6391d8a6033c7a415d87cb5aa13daef67196a Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 19 Oct 2019 08:41:17 +0200 Subject: [PATCH] Implement Error for ExitCode Signed-off-by: Matthias Beyer --- lib/core/libimagerror/src/exit.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/core/libimagerror/src/exit.rs b/lib/core/libimagerror/src/exit.rs index 40ac9b9f..85ae5466 100644 --- a/lib/core/libimagerror/src/exit.rs +++ b/lib/core/libimagerror/src/exit.rs @@ -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 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 { fn unwrap_or_exit(self) -> T; }