diff options
author | Thomas Voss <mail@thomasvoss.com> | 2023-07-29 01:07:35 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2023-07-29 01:07:35 +0200 |
commit | 0218e1a4327f317f3aa16ea83b1a52019d5c37a0 (patch) | |
tree | 23b585510bb83ee327d4f0c59234707153376649 /src/main_result.rs |
Genesis commit
Diffstat (limited to 'src/main_result.rs')
-rw-r--r-- | src/main_result.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/main_result.rs b/src/main_result.rs new file mode 100644 index 0000000..36e3096 --- /dev/null +++ b/src/main_result.rs @@ -0,0 +1,32 @@ +use std::{ + io::{self, Write}, + process::{ExitCode, Termination}, +}; + +use super::error::Error; + +pub enum MainResult { + Success, + Failure(Error), +} + +impl Termination for MainResult { + fn report(self) -> ExitCode { + match self { + Self::Success => ExitCode::SUCCESS, + Self::Failure(e) => { + let _ = write!(io::stderr(), "{e}"); + ExitCode::FAILURE + } + } + } +} + +impl From<Result<(), Error>> for MainResult { + fn from(r: Result<(), Error>) -> Self { + match r { + Ok(()) => Self::Success, + Err(e) => Self::Failure(e), + } + } +} |