You can return from a function before reaching the last statement can be done using return
:
fn example() -> i32 {
if true {
return 1;
}
0 // this line is never reached
}
Is it possible to do something similar with block expressions?
let foo = {
if true {
// somehow "return" so that foo is 1
}
0 // this line is never reached
};
In this example I could have used an if
-else
, but I'm asking about block expressions in general.