-
Book Overview & Buying
-
Table Of Contents
The Rust Programming Handbook
By :
Closures beautifully shape behavior in a clear way, especially when working with iterators. Rust’s pattern matching adds even more expressive power to our code. Having already looked at the match statement, let’s now take a dive into it from a functional perspective, seeing how it neatly destructures data and guides our control flow, perfectly complementing closure-based transformations.
We saw match used extensively in error handling (Chapter 6) and with enums (Chapter 5). Pattern matching is also a key feature often associated with functional programming languages, and Rust’s implementation is particularly powerful. It allows you to destructure data types and control program flow based on the shape of the data, not just its value.
match arms can directly destructure structs and enums, binding parts of their data to variables within the arm’s scope: