32 lines
653 B
Rust
32 lines
653 B
Rust
use std::process::{ExitCode, Termination};
|
|
|
|
use crate::How;
|
|
|
|
pub enum TerminationResult {
|
|
Ok,
|
|
Err(How),
|
|
}
|
|
|
|
impl Termination for TerminationResult {
|
|
fn report(self) -> ExitCode {
|
|
match self {
|
|
Self::Ok => ExitCode::SUCCESS,
|
|
Self::Err(e) => {
|
|
use std::io::Write;
|
|
let _ = writeln!(std::io::stderr(), "{e}");
|
|
|
|
ExitCode::FAILURE
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<Result<(), How>> for TerminationResult {
|
|
fn from(value: Result<(), How>) -> Self {
|
|
match value {
|
|
Ok(()) => Self::Ok,
|
|
Err(e) => Self::Err(e),
|
|
}
|
|
}
|
|
}
|