blob: 36e3096a6806d11367814911bc3f0ec95c8f63de (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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),
}
}
}
|