2 ms·
Building on the more practical example, this sort of conditional early return is extremely common in Rust, because expression-orientation makes it very pleasant
by chrismorgan 6y ago
Building on the more practical example, this sort of conditional early return is extremely common in Rust, because expression-orientation makes it very pleasant to use. Here’s a sketch of some of the sorts of ways it can happen in state machine:
loop {
// …
state = match state {
A => B, // normal
B => break, // exits the loop
C => { …; continue; }, // does something and then returns to the start of the loop, skipping setting the state and anything else
D => return, // exits the whole thing
E => f()?, // if f() returns an Err or None or similar, it’ll return early
};
// …
}