liveBook · Manning

Match statement

A match statement is a programming or query construct that compares a value or pattern against alternatives to select corresponding behavior or results.

How 2 Manning books explain it

Rust Servers, Services, and Apps

A match statement is a Rust control-flow construct that selects behavior by matching a value against patterns.

How it is used
Uses pattern matching to handle successful and failed computations in Rust error-handling and Actix Web request paths.
How deep it goes
Explains worked Result branches, custom error formatting, and HTTP propagation before introducing the shorter ? operator.
Examples
Uses integer parsing, squaring, custom parse and I/O errors, and an Actix Web file-reading handler.
What you can do after
Apply match statements to branch on Rust Result values and propagate failures through Actix Web handlers.

Read how Rust Servers, Services, and Apps explains match statement →

Refactoring to Rust

A match expression is Rust's pattern-matching control-flow expression that selects and evaluates an arm based on a value's structure or variant.

How it is used
Uses match to turn FizzBuzz results into output and to handle success or propagate errors.
How deep it goes
Explains enum-arm selection, payload binding, and match as a value that can return early on Err.
Examples
Uses FizzBuzz variants, including a data-carrying NotDivisible variant, and matches Result with an early error return.
What you can do after
Apply it via Rust to dispatch enum variants, bind variant data, and handle Result errors with explicit early returns.

Read how Refactoring to Rust explains match statement →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.