rustutils-runnable 0.1.0

Trait for a runnable utility that exits with an ExitCode
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use std::error::Error;
use std::process::ExitCode;

pub trait Runnable {
    /// Run something, can either succeed or fail.
    fn run(&self) -> Result<(), Box<dyn Error>>;

    /// Run somethin, returning an ExitCode to return to the OS.
    fn main(&self) -> ExitCode {
        match self.run() {
            Ok(()) => ExitCode::SUCCESS,
            Err(error) => {
                eprintln!("Error: {error}");
                ExitCode::FAILURE
            }
        }
    }
}