Hacker News new | ask | show | jobs
by smaddox 2726 days ago
You should try using `map_err` and the `?` operator, with your own error enum defined using the `failure_derive` crate, for example:

    foo().map_err(|e| MyError::FooError(e))?
      .bar().map_err(|e| MyError::BarError(e))?;
2 comments

A tip - you usually don't need lambdas in such cases; this should work:

    foo().map_err(MyError::FooError)?
      .bar().map_err(MyError::BarError)?;
Oh, nice! I did not realize tuple constructors implemented `FnOnce`! Thanks for the tip!
d'oh - you beat me to it ;)