This is also somewhat common in c++ with immediate-invoked lambdas
let config: Result<i32, i32> = {
Ok(
"1234".parse::<i32>().map_err(|_| -1)?
)
};
would fail to compile, or worse: would return out of the entire method if surrounding method would have return type Result<_,i32>. On the other hand, let config: Result<i32, i32> = (||{
Ok(
"1234".parse::<i32>().map_err(|_| -1)?
)
})();
runs just fine.Hopefully try blocks will allow using ? inside of expression blocks in the future, though.
And the workarounds often make the pattern be a net loss in clarity.