2 ms·
Specifically the ? symbol is currently implemented via the operator trait Try as Try::branch() which gets you a ControlFlow If Try::branch gives us a ControlFl
by tialaramex 1y ago
Specifically the ? symbol is currently implemented via the operator trait Try as Try::branch() which gets you a ControlFlow
If Try::branch gives us a ControlFlow::Break we're done here, return immediately with the value wrapped by Break [if any] inside an Err, otherwise we have ControlFlow::Continue wrapping a value we can use to continue with execution of this function.
This is type checked, so if the function says it returns Result<Goose, Dalek> then the type of the value wrapped in a ControlFlow::Break had better be Err(Dalek) or else we can't use our ? operator here.
Reifying ControlFlow here separates concerns properly - if we want to stop early successfully then control flow can represent that idea just fine whereas an Exception model ties early exit to failure.