whaterror

Crates.iowhaterror
lib.rswhaterror
version0.1.0
sourcesrc
created_at2021-01-09 17:24:16.963758
updated_at2021-01-10 01:50:01.059412
descriptionCustomizable handling for fallible main
homepage
repositoryhttps://github.com/leo60228/whaterror
max_upload_size
id336812
size10,473
leo60228 (leo60228)

documentation

README

whaterror

There is nothing at all in your return type, useful or otherwise.

Proc macro attribute for a more customizable alternative to the standard library's Termination trait.

As a simple example, this replicates the standard behavior for fn main() returning Result<T, E>:

use whaterror::whaterror;

#[whaterror(|err| eprintln!("Error: {:#?}", err))]
fn main() -> Result<(), Error> {
    Err(Error::Failed)
}

If your handler returns, whaterror will automatically exit with code 1 (or panic if inside a test).

This also works for Option<T>:

use whaterror::whaterror;

#[whaterror(|| eprintln!("returned None"))]
fn main() -> Option<()> {
    None
}

The || isn't necessary in this case, since there are no arguments:

use whaterror::whaterror;

#[whaterror(unreachable!())]
fn main() -> Option<()> {
    Some(())
}

This works for non-() types just like you would expect. Non-main functions are technically allowed, but currently have very strict limitations. These limitations are planned to be lifted in the future.

Commit count: 23

cargo fmt