Tour of Rust Table of Contents

Returning Values From Block Expressions

if, match, functions, and scope blocks all have a unique way of returning values in Rust.

If the last statement in an if, match, function, or scope block is an expression without a ;, Rust will return it as a value from the block. This is a great way to create concise logic that returns a value that can be put into a new variable.

Notice that it also allows an if statement to operate like a concise ternary expression.