by koakuma-chan · 11mo ago · 0 comments
https://doc.rust-lang.org/beta/unstable-book/language-featur...
You only live once.
let x = (|| -> Result<i32, std::num::ParseIntError> {
Ok("1".parse::<i32>()?
+ "2".parse::<i32>()?
+ "3".parse::<i32>()?)
})();This works fine: https://play.rust-lang.org/?version=stable&mode=debug&editio...
The closest thing I can think of that will let you return a result from within a separate scope using a set of foo()? calls would be a lambda function that's called immediately, but that has its own problems when it comes to moving and it probably doesn't compile to very fast code either. Something like https://play.rust-lang.org/?version=stable&mode=debug&editio...