A match statement is a Rust control-flow construct that selects behavior by matching a value against patterns.
A match statement branches on Result variants, extracting successful values with Ok and handling failures with Err. section 5.2
Square a parsed integer
The square function matches val.parse::<i32>(), squares the number in the Ok arm, and returns the parsing error unchanged in the Err arm. Calling it with "2" produces Ok(4); calling it with "INVALID" produces a ParseIntError.
How Rust Servers, Services, and Apps covers it
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.
How it connects
Connects match statements to Result, enums, error handling, the ? operator, and Actix Web.
Refactoring to RustA match expression is Rust's pattern-matching control-flow expression that selects and evaluates an arm based on a value's structure or variant.
pattern matchingimplements · Pattern matching is the process of comparing data or values with specified or learned patterns to identify correspondence, conformity, or a matching case.
graph patternuses · A graph pattern is a declarative representation of nodes, relationships, and property constraints used to describe graph structures to match.
case statementequivalent to · A case or switch construct is a conditional control-flow construct that selects a branch or result from alternatives by matching a value or testing conditions.
Cypherpart of · Cypher is a declarative graph query language for expressing patterns and retrieving, creating, or modifying property-graph data.
result typeuses · A type that represents an operation’s outcome as either a successful value or a failure value.
enumuses · An enum is a type or language construct whose values are selected from a finite set of named alternatives, which may carry associated data.
This explainer was generated by Manning's knowledge graph from the text of Rust Servers, Services, and Apps. The section links point to the parts of the book it draws on.