-
Book Overview & Buying
-
Table Of Contents
Design Patterns and Best Practices in Rust
By :
Expression-oriented programming, where blocks return values, has deep roots in functional programming. Lisp and its descendants made everything an expression. ML, Scheme, Haskell, OCaml, Scala, and Ruby all treat blocks as expressions that return values. This isn't a Rust innovation but a fundamental concept from functional and expression-oriented languages.
What Rust adds is combining expression-oriented programming with the language's guarantees. Blocks in Rust must respect ownership and borrowing rules. The compiler ensures that values returned from blocks are properly moved or borrowed. This integration of expression-oriented programming with compile-time memory safety makes complex initialization both safe and zero-cost, bringing functional programming elegance to systems code.
In many languages, statements do things and expressions produce values. In Rust, however, almost everything is an expression, including blocks, by which we mean...