Auto-complete your functions to use ?
expressions and return anyhow::Result
with less boilerplate!
For convenience, anyhoo
reexports anyhow
as anyhoo::anyhow
:
[dependencies]
anyhoo = { git = "https://github.com/tranzystorek-io/anyhoo", features = ["reexport"] }
You can opt out of this feature if you're using a particular version of anyhow
.
A function that reads a line and parses it to an integer.
Default rusty idiom:
fn parse_line() -> anyhow::Result<i32> {
let mut input = String::new();
std::io::stdin().read_line(&mut input)?;
let result = input.parse();
Ok(result)
}
With anyhoo
:
#[anyhoo::anyhoo]
fn parse_line() -> i32 {
let mut input = String::new();
std::io::stdin().read_line(&mut input)?;
input.parse()?
}