Skip to content

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

Notifications You must be signed in to change notification settings

leo60228/whaterror

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages