iximiuz.com
...MatchOp,
}
/// Parses a label matching operation.
///
/// ```
/// # use nom_parser_example::naive::{label_match, LabelMatch, MatchOp};
/// #
/// # fn main() {
/// assert_eq!(
/// label_match(r#"foo=="bar""#),
/// Ok(("", LabelMatch { label: "foo", value: "bar", op: MatchOp::Eql }))
/// );
/// assert_eq!(
/// label_match(r#"foo!~"2..""#),
/// Ok(("", LabelMatch { label: "foo", value: "2..", op: MatchOp::NeqRe }))
/// );
/// # }
/// ```
pub...
Rust Walkthroughs
2021-07-28
~15 min read
manishearth.github.io
...u8 = ...; // A_const
let A @ _ = ...; // A_let
match .. {
A => ...; // A_match
}
What happens here is that constants and variables occupy the same namespace. So A_let shadows
A_const here, and when we attempt to match, A_match is resolved to A_let and rejected (since
you can’t match...
News & Blog Posts
2018-04-17
~6 min read
github.com
## Summary
Rust currently forbids pattern guards on match arms with move-bound variables.
Allowing them would increase the applicability of pattern guards.
## Motivation
Currently, if you attempt to use guards on a match arm with a move-bound
variable, e.g.
```rust
struct A { a: Box<int> }
fn foo(n...
RFC 107
RFC
2014-06-05
~3 min read
doc.rust-lang.org
...macro_rules! example {
($e:expr) => { println!("first rule"); };
(const $e:expr) => { println!("second rule"); };
}
fn main() {
example!(const { 1 + 1 });
}
Here, in the 2021 Edition, the macro will match the second rule. If earlier editions had changed expr to match the newly introduced const expressions, then it would match the...
The Rust Edition Guide
Book
2024-01-01
~1 min read
github.com
...the existing `.contains()` method is incompatible with Needle API)
* `.find()`, `.rfind()`, `.find_range()`, `.rfind_range()`
* `.matches()`, `.matches_mut()`, `.rmatches()`, `.rmatches_mut()`
* `.match_indices()`, `.match_indices_mut()`, `.rmatch_indices()`, `.rmatch_indices_mut()`
* `.match_ranges()`, `.match_ranges_mut()`, `.rmatch_ranges()`, `.rmatch_ranges_mut()`
* `.trim_matches()`, `.trim_start_matches()`, `.trim_end_matches()`
* `.replace...
RFC 2500
RFC
2018-07-06
~41 min read
rust-leipzig.github.io
...Matches
Regarding the found matches I found some deviations. At first, the libraries oniguruma and tre do not support
Unicode category expressions like \p{Sm}. This expression matches all mathematical symbols like = or |.
The Rust regex crate matches additionally the symbol ∞.
Hyperscan returns more matches than other engines, e.g...
News & Blog Posts
2017-04-04
~7 min read
gaultier.github.io
...But not for match.
Alright, so after some searching around, I came up with this mouthful of a syntax:
Rust1 let value = match left.try_into() {
2 Ok(v) => v,
3 Err::<_, TryFromSliceError>(err) => {
4 // [...]
5 }
6 };
Which works! And the same syntax can be applied to the Ok branch...
Rust Walkthroughs
2025-02-12
~5 min read
adventures.michaelfbryan.com
...Matcher> Matcher for FallingEdge<M> {
fn matches_event(&mut self, event: &Event<'_>) -> bool {
let current_is_matched = self.inner.matches_event(event);
let is_falling_edge = self.previous_was_matched && !current_is_matched;
self.previous_was_matched = current_is_matched;
is_falling_edge
}
}
For convenience we can add a combinator...
News & Blog Posts
2020-02-11
~14 min read
beeb.li
...For each match, we see a couple of lines of context with line numbers above and below. The selected match is indicated
by a yellow chevron in the gutter. Each individual match can be toggled to be skipped during replacement
with s. The match appears in dimmed text if skipped...
Project/Tooling Updates
2026-05-20
~16 min read
blog.sheerluck.dev
...And we matched on it:
let regex = match Regex::new(pattern) {
Ok(r) => r,
Err(e) => {
eprintln!("Invalid pattern: {}", e);
std::process::exit(1);
}
};
Now we're going to go much deeper.
Pattern Matching on Result
Just like Option, you can match on Result:
match result {
Ok(value) => println!("success...
Rust Walkthroughs
2026-05-06
~27 min read
github.com
...On floats are raw pointers, pattern matching behaves like `==`,
which means in particular that the value `-0.0` matches the pattern `0.0`, and NaN values match no pattern (except for wildcards).
### Breaking changes
This RFC breaks code that compiles today, but only code that already emits a future compatibility...
RFC 3535
RFC
2023-11-19
~17 min read
github.com
...maybe_label FOR top_pat IN expr_nostruct block ;
```
For `match` expressions we now have:
```rust
expr_match : MATCH expr_nostruct '{' match_clause* nonblock_match_clause? '}' ;
match_clause : nonblock_match_clause ',' | block_match_clause ','? ;
nonblock_match_clause : match_arm (nonblock_expr | block_expr_dot) ;
block_match_clause : match_arm (block...
RFC 2535
RFC
2018-08-29
~19 min read
home.expurple.me
Table of ContentsThe “Error Handling” seriesLibrary vs application needsDon’t use one big enum for everythingModularityPrecise signaturesFlat vs nested enumsFlat enumsNested enumsWorkarounds for pattern matching nested enumsOther tipsWhen to reuse an error type between multiple functionsWhere to put error typesDon’t create one-variant enumsnon_exhaustiveNaming error variantsPrivacy of fieldsMixing...
Rust Walkthroughs
2026-01-28
~12 min read
morestina.net
Let’s say you need to match the same regex across a large number of strings – perhaps you’re applying a grep-like filter to data generated or received by your program. This toy example demonstrates it by matching a regex against half a billion strings:
use regex::Regex;
lazy...
Observations/Thoughts
2022-10-26
~3 min read
aarol.dev
...Key) -> &'static str {
use Key::*;
match *LANG {
Lang::En => match key {
battery_remaining => "remaining",
no_adapter_found => "No headphone adapter found",
view_logs => "View logs",
view_updates => "View updates",
quit_program => "Close",
device_charging => "(Charging)",
device_disconnected => "(Disconnected)",
version => "Version",
},
Lang::Fi => match key {
battery_remaining => "jäljellä",
no_adapter_found...
Observations/Thoughts
2025-05-14
~2 min read
github.com
## Summary
Change pattern matching on an `&mut T` to `&mut <pat>`, away from its
current `&<pat>` syntax.
## Motivation
Pattern matching mirrors construction for almost all types, *except*
`&mut`, which is constructed with `&mut <expr>` but destructured with
`&<pat>`. This is almost certainly an unnecessary inconsistency.
This can and does lead...
RFC 179
RFC
2015-01-04
~2 min read
rust-analyzer.github.io
...SSR now matches paths based on whether they resolve to the same thing instead of whether they’re written the same.
So foo() won’t match foo() if it’s a different function foo(), but will match bar::foo() if it’s the same foo.
Paths in the replacement will...
Tooling
2020-07-28
~1 min read
github.com
...An individual
`#[cfg(...)]` attribute "matches" if *all* of the contained cfg patterns match
the compilation environment, and an item preserved if it *either* has no
`#[cfg(...)]` attributes or *any* of the `#[cfg(...)]` attributes present
match.
This is problematic for several reasons:
* It is excessively verbose in certain situations. For example...
RFC 194
RFC
2014-08-09
~3 min read
doc.rust-lang.org
...The type of the body is `!` which matches the return type.
}
fn not_diverging() -> ! {
// This type is uninhabited.
// However, the entire function is not considered diverging.
make_empty();
// ERROR: The type of the body is `()` but expected type `!`.
}
[!NOTE] Divergence can propagate to the surrounding block. See [expr.block.diverging...
The Rust Reference
Book
2024-01-01
~1 min read
jdrouet.github.io
...Option<AttributeIndex>,
filter: &TextFilter,
) -> HashMap<EntryIndex, f64> {
let matching_terms = match filter {
TextFilter::StartsWith { prefix } => self.trienodes().search(prefix),
TextFilter::Matches { value } => self.trigrams().search(value),
TextFilter::Equals { value } => self.inner.get_term(value).into_iter(),
};
let matching_entries = self.reduce_matches(attribute, matching_terms)
self.compute_scores(attribute, matchings...
Rust Walkthroughs
2025-04-16
~13 min read