Pattern Matching

1

match and Pattern Matching in Depth

6 minute

C programmers often first read match as a stricter switch.

That comparison helps at the beginning, but it is incomplete. C switch mainly branches on integer values. If the state also carries data, you still manually read fields from a struct or union.

Rust match performs pattern matching:

check what shape a value has, and bind the data inside that shape.

Earlier, when discussing enum, we used Rust enums as a safer replacement for C tagged unions. This article continues from there: how match handles richer state, references, conditions, and local unpacking.

Read More