Re:Rust Language Cheat Sheet
by dbaupp on Tuesday August 06, 2019 @04:07AM
(#20623203)
I think it is better to not think of ; (or lack of ;) as an "active" return: it isn't like the `return` keyword.
If the last statement/expression in a block is an expression not followed by ;, the block evaluates to that expression. Otherwise (such as, the last expression has a ;), the block evaluates to ().
The function "return" behaviour is because function bodies are blocks: a function returns the value of its block (or any `return`).
If the last statement/expression in a block is an expression not followed by ;, the block evaluates to that expression. Otherwise (such as, the last expression has a ;), the block evaluates to ().
The function "return" behaviour is because function bodies are blocks: a function returns the value of its block (or any `return`).