FWIW there are third-party libraries which include that feature e.g. error_chain has a `quick_main` macro (working with its `error_chain!`-generated error, but I'm not sure it actually depends on it):
quick_main!(|| -> Result<()> {
// insert Result-returning code here
});
Alternatively it takes a few lines to bootstrap it by hand e.g. ripgrep uses this code to bootstrap: fn main() {
match Args::parse().map(Arc::new).and_then(run) {
Ok(0) => process::exit(1),
Ok(_) => process::exit(0),
Err(err) => {
eprintln!("{}", err);
process::exit(1);
}
}
}
https://github.com/BurntSushi/ripgrep/blob/master/src/main.r...
Re:Announcing Tokio 0.1
by steveklabnik on Wednesday January 11, 2017 @02:42PM
(#13376844)
Yes, and that discussion is still ongoing. The devil, as always, is in the details.
Re:Announcing Tokio 0.1
by JoshTriplett on Wednesday January 11, 2017 @03:06PM
(#13377052)
`-> impl Trait` seems useful in that context, so that main could have a variety of appropriate return value types: `()`, `i32` (for an exit code), or `Result<T, E>` where T implements ReturnValue and E implements Error.
`quick_error` uses a trait like that to determine the exit code of `main()`, allowing it to return either () or i32.
If rust had that examples would be even shorter using ? Instead of try! or unwrap