Syntax

Rust Match Expression Syntax

In Rust, match expression: matches a value against patterns — match n { 1 => "one", _ => "other", }

Quick Answer

Syntax
match n { 1 => "one", _ => "other", }
RustSyntax

Match Expression

Code example
match n { 1 => "one", _ => "other", }

Matches a value against patterns.

Learn More

How to match expression in Rust

  1. Open your Rust file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Rust Match Expression Syntax

Use match n { 1 => "one", _ => "other", }.

Related Syntax References

Frequently asked questions

What is the Rust syntax for match expression?

Use this pattern: match n { 1 => "one", _ => "other", }

Can I copy this Rust code example?

Yes. Use Copy code and adapt the example to your program.

Is this Rust syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify