docs.rs
Regex matching on character and byte streams.
matchers Regular expression matching on Rust streams. Overview The regex crate implements regular expression matching on strings and byte arrays. However, in order to match the output of implementations of fmt::Debug and fmt::Display , or by any code which writes to an...
Crate
v0.2.0
2024-07-01
doc.rust-lang.org
...fn age() -> u32 {
15
}
fn main() {
println!("Tell me what type of person you are");
match age() {
0 => println!("I haven't celebrated my first birthday yet"),
// Could `match` 1 ..= 12 directly but then what age
// would the child be?
// Could `match` n and use an `if` guard, but would...
Rust by Example
Book
2024-01-01
~1 min read
github.com
...Like the `for` loop before it, this construct can be transformed in a syntax-lowering pass into the
equivalent `match` statement. The `expression` is given to `match` and the `pattern` becomes a match
arm. If there is an `else` block, that becomes the body of the `_ => {}` arm, otherwise `_ => {}` is
provided...
RFC 160
RFC
2014-08-26
~5 min read
trifectatech.org
...when #[loop_match] and #[const_continue] are configured out (e.g. with #[cfg_attr(feature = "loop_match", loop_match)]), the code behaves like before.
Benchmarks
So, how much does this help? As always, it depends.
Your algorithm must actually look like a loop with a match to benefit at all...
Observations/Thoughts
2025-09-10
~9 min read
xd009642.github.io
...impl Match for BinaryStreamMatcher {
fn temporal_match(&self, match_state: &mut MatchState) -> Option<bool> {
let json = ValidJsonMatcher;
let len = match_state.len();
let last = match_state.last();
if len == 1 && json.unary_match(last).unwrap() {
match_state.keep_message(0);
Some(true)
} else if last.is_binary() {
// We won't...
Project/Tooling Updates
2025-03-05
~3 min read
sailor.li
...running 3 tests
test accursed_match ... bench: 1,681.19 ns/iter (+/- 245.20)
test optimised_match ... bench: 1,681.06 ns/iter (+/- 261.87)
test regular_match ... bench: 2,339.23 ns/iter (+/- 74.51)
Using arrays of [0u8; 16384]:
test accursed_match ... bench: 9,373.10 ns/iter...
Rust Walkthroughs
2025-08-27
~5 min read
adventures.michaelfbryan.com
Rust 1.26 introduced a nifty little feature called Basic Slice
Patterns which lets you pattern match on slices with a known length. Later on
in Rust 1.42, this was extended to allow using .. to match on
“everything else”.
As features go this may seem like a small addition...
Rust Walkthroughs
2021-08-18
~3 min read
systemf.epfl.ch
...The brown lookbehind has
n
=
1
since it always matches exactly 1 character.
m
=
2
because that is the shortest matching length of aa.
The blue lookbehind has
n
=
2
since it always matches exactly 2 characters. The surrounding
lookbehinds do not contribute to the match length.
m
=
1
because...
Observations/Thoughts
2025-07-16
~27 min read
graphallthethings.com
...Column) -> Vec<u8> {
match column {
Column::I32(values) => compress_generic(values),
Column::F32(values) => compress_generic(values),
Column::String(values) => compress_generic(values),
...
}
}
Something like that!
Match clauses everywhere!
Extremely tedious to work with.
Eventually I closed shop on PancakeDB (entirely because of the match clauses, of course), but I...
Rust Walkthroughs
2024-11-20
~4 min read
doc.rust-lang.org
...let Config { window_width, window_height } = config;
let Token = token;
let Id(id_number) = id;
let error = Error::Other;
let message = Message::Reaction(3);
// Non-exhaustive enums can be matched on exhaustively within the defining crate.
match error {
Error::Message(ref s) => { },
Error::Other => { },
}
match message {
// Non-exhaustive variants can...
The Rust Reference
Book
2024-01-01
~4 min read
blog.sheerluck.dev
In this post, we are going to learn about structs, enums and pattern matching in Rust. Once we cover all these concepts, we will build a JSON Parser in Rust from scratch. I'm really excited about this project. Let's start.
Get the source code from here
Structs in...
Rust Walkthroughs
2026-04-29
~43 min read
github.com
...Lastly, there are alternatives that don't seem very favorable, but are listed for completeness sake:
- Remove `unsafe` from the API by returning a special `SubSlice<'a>` type instead of `(uint, uint)` in each
match, that wraps the haystack and the
current match as a `(*start, *match_start, *match_end...
RFC 528
RFC
2015-02-17
~16 min read
doc.rust-lang.org
pub fn split<F>(&self, pred: F) -> Split<'_, T, F>
slice::split — Returns an iterator over subslices separated by elements that match pred. The matched element is not contained in the subslices.
Examples
let slice = [10, 40, 33, 20];
let mut iter = slice.split(|num| num % 3 == 0);
assert_eq!(iter.next().unwrap(), &[10, 40]);
assert_eq!(iter.next().unwrap...
method
core
Stable since 1.0.0
Version 1.100.0-nightly
docs.rs
...clap_complete_command::Shell, }, } fn main() { let cli = Cli::parse(); match cli.command { // e.g. `$ cli completions bash` Commands::Completions { shell } => { shell.generate(&mut Cli::command(), &mut std::io::stdout()); } } } Builder use clap::{Arg, Command}; fn build_cli() -> Command { Command::new(env!("CARGO_PKG_NAME")) .subcommand_required(true) .subcommand( Command...
Crate
v0.6.1
2024-07-14
audunhalland.github.io
...Note that the matching!() macro uses pattern matching by default.
Printing a Debug-based diff on a pattern mismatch might not produce a good diff output, since patterns could be much smaller than the actuall value due to spreads or other variations in syntax.
matching!() now also supports matching using...
Project/Tooling Updates
2022-11-30
~3 min read
github.com
...The following snippet (written with this RFC):
```rust
if let A(x) | B(x) = expr {
do_stuff_with(x);
}
```
must be written as:
```rust
if let A(x) = expr {
do_stuff_with(x);
} else if let B(x) = expr {
do_stuff_with(x);
}
```
or, using `match`:
```rust
match expr {
A...
RFC 2175
RFC
2017-10-16
~7 min read
rustc-dev-guide.rust-lang.org
...It uses JSONPath as a query language, which takes a path, and returns a list of values that that path is said to match to.
Directives
• //@ has <path>: Checks <path> exists, i.e. matches at least 1 value.
• //@ !has <path>: Checks <path> doesn't exist, i.e. matches 0 values...
Guide to Rustc Development
Book
2024-01-01
~2 min read
www.sheshbabu.com
...Each PATTERN => EXPRESSION combination is called a match arm.
The above example doesn’t really convey how useful pattern matching is - it just looks like switch case with a different syntax and a fancy name. Let’s talk about destructuring and enums to understand why pattern matching is useful.
DestructuringDestructuring...
News & Blog Posts
2020-07-14
~8 min read
doc.rust-lang.org
Patterns and Matching
Patterns are a special syntax in Rust for matching against the structure of types, both complex and simple. Using patterns in conjunction with match expressions and other constructs gives you more control over a program’s control flow. A pattern consists of some combination of the following...
The Rust Programming Language
Book
2024-02-01
~1 min read
serokell.io
...each operation requires its own nested match statement.
How a safe_division_thrice function looks with match vs. ?
With pattern matching
fn safe_division_thrice(a: i32, b: i32, c: i32, d: i32) -> Option<i32> {
match safe_division(a, b) {
Some(x) => match safe_division(x, c) {
Some(y) => safe...
Rust Walkthroughs
2022-10-26
~13 min read