Crates.io | whaterror |
lib.rs | whaterror |
version | 0.1.0 |
source | src |
created_at | 2021-01-09 17:24:16.963758 |
updated_at | 2021-01-10 01:50:01.059412 |
description | Customizable handling for fallible main |
homepage | |
repository | https://github.com/leo60228/whaterror |
max_upload_size | |
id | 336812 |
size | 10,473 |
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.