mcmah309.github.io
...Option<f64>) {
self.ranking_score_threshold = threshold;
}
}
impl HasTermsMatchingStrategy for KeywordSearch<'_> {
fn get_terms_matching_strategy(&self) -> &TermsMatchingStrategy {
&self.terms_matching_strategy
}
fn set_terms_matching_strategy(&mut self, strategy: TermsMatchingStrategy) {
self.terms_matching_strategy = strategy;
}
}
impl HasScoringStrategy for KeywordSearch<'_> {
fn get_scoring_strategy(&self) -> &ScoringStrategy {
&self.scoring_strategy
}
fn...
Rust Walkthroughs
2025-06-11
~17 min read
corentin-core.github.io
...let list = hlist![1i32, "hello", 3.14f64];
let (matched, leftover) = list.sculpt::<HList!(f64, i32), _>();
// matched : HList!(3.14f64, 1i32)
// leftover : HList!("hello")
The compiler walks the source HList, plucks each requested type by recursing until it finds a match, builds the matched tuple, returns what’s left.
Two failure...
Rust Walkthroughs
2026-06-24
~16 min read
rust-lang.github.io
...In particular, at the time that mailing list thread was created, the code match match x {} ... would be parsed as match (x {}) ..., not as (match x {}) ... (see Rust PR 5137); likewise, if x {} would be parsed as an if-expression whose test component is the struct literal x {}. Thus, at...
RFC 218
RFC
2014-08-28
~12 min read
depth-first.com
...pub enum Element {
Ac,
B,
Br,
// ...
}
pub enum Error {
Character(usize)
}
pub fn element(scanner: &mut Scanner) -> Result<Option<Element>, Error> {
match scanner.peek() {
Some('A') => {
scanner.pop();
match scanner.peek() {
Some('c') => {
scanner.pop();
Ok(Some(Element::Br))
},
_ => Err(Error::Character(scanner.cursor()))
}
},
Some('B') => {
scanner.pop();
match scanner...
Rust Walkthroughs
2021-12-22
~12 min read
rust-lang.github.io
...match map.entry(key) => {
Entry::Vacant(entry) => { entry.insert(1); },
Entry::Occupied(entry) => { *entry.get_mut() += 1; },
}
match map.entry(key) => {
Entry::Vacant(entry) => { entry.insert(vec![val]); },
Entry::Occupied(entry) => { entry.get_mut().push(val); },
}
This code is noisy, and is visibly fighting the Entry API a bit, such...
RFC 921
RFC
2015-03-01
~2 min read
rreverser.com
...Macros currently don't allow matching literals, and expr won't work for us because it can accidentally match sequence like 2 + 3 ... instead of taking just a single number, so we'll resort to tt - a generic token matcher that matches only one token tree (whether it's a...
News & Blog Posts
2018-01-16
~13 min read
doc.rust-lang.org
...Condition operands must be either an [Expression] with a boolean type or a conditional let match. If all of the condition operands evaluate to true and all of the let patterns successfully match their scrutinees, then the loop body block executes.
After the loop body successfully executes, the condition operands...
The Rust Reference
Book
2024-01-01
~8 min read
www.sheshbabu.com
...Ignore the error
Terminate the program
Use a fallback value
Bubble up the error
Bubble up multiple errors
Match boxed errors
Libraries vs Applications
Create custom errors
Bubble up custom errors
Match custom errors
Ignore the errorLet’s start with the simplest scenario where we just ignore the error. This...
Learn Standard Rust
2020-08-04
~11 min read
doc.rust-lang.org
...The scrutinee is the expression being matched on in the if let expression.
Migration
It is always safe to rewrite if let with a match. The temporaries of the match scrutinee are extended past the end of the match expression (typically to the end of the statement), which is the...
The Rust Edition Guide
Book
2024-01-01
~3 min read
rustc-dev-guide.rust-lang.org
...for<'a> Foo<&'a isize> and we match this impl. What obligation is generated as a result? We want to get Baz: for<'a> Bar<&'a isize>, but how does that happen?
After the matching, we are in a position where we have a placeholder substitution like X => &'0 isize...
Guide to Rustc Development
Book
2024-01-01
~3 min read
doc.rust-lang.org
...the parser tries alternatives left to right and takes the first that matches. If an alternative fails partway through a sequence, the parser normally backtracks and tries the next alternative. The cut operator (^) prevents this. Once every expression to the left of ^ in a sequence has matched, the rest of...
The Rust Reference
Book
2024-01-01
~3 min read
rustc-dev-guide.rust-lang.org
...The result looks like this:
$ perf focus '{do_mir_borrowck}' --tree-callees --tree-min-percent 3
Matcher : {do_mir_borrowck}
Matches : 577
Not Matches: 746
Percentage : 43%
Tree
| matched `{do_mir_borrowck}` (43% total, 0% self)
: | rustc_borrowck::nll::compute_regions (20% total, 0% self)
: : | rustc_borrowck::nll::type_check...
Guide to Rustc Development
Book
2024-01-01
~9 min read
doc.rust-lang.org
...u32) -> u32 {
let mut acc = 0;
for i in 0..up_to {
// Notice that the return type of this match expression must be u32
// because of the type of the "addition" variable.
let addition: u32 = match i%2 == 1 {
// The "i" variable is of type u32, which is perfectly fine...
Rust by Example
Book
2024-01-01
~1 min read
siciarz.net
...So let's use pattern matching to find
color by name:
pub fn find_color(name: &str) -> Option<Color> {
match name.to_lowercase().as_str() {
"amber" => Some(Color { r: 255, g: 191, b: 0 }),
// hundreds of other names...
"zinnwaldite brown" => Some(Color { r: 44, g: 22, b: 8 }),
_ => None,
}
}
The...
24 Days of Rust
2016-12-13
~3 min read
blog.knoldus.com
...extern crate movie_genres;
use movie_genres::Genres;
fn main() {
let genres = Genres::Horror;
match genres {
Genres::Horror => println!("Horror Movie!!"),
Genres::Comedy => println!("Comedy Movie!!"),
Genres::Romance => println!("Romance Movie!!"),
}
}
Now if we hit cargo run, we will get a compilation error.
Now add wildcard arm in match expression...
Learn Standard Rust
2020-08-04
~1 min read
lwn.net
...This makes
it easier to write rules that match two different call sites separated by some
arbitrary code.
Matching a pattern that contains an ellipsis requires considering different
potential matches, which means considering multiple alternatives, so it is a
form of disjunction.
Previously, Coccinelle only permitted
disjunctions of expressions; now...
Project/Tooling Updates
2024-10-02
~4 min read
viruta.org
...replace AcceptLanguage::any_matches -> bool with false
rsvg/src/accept_language.rs:136:9: replace AcceptLanguage::any_matches -> bool with true
Now look at the corresponding lines in the source:
... impl AcceptLanguage {
135 fn any_matches(&self, tag: &LanguageTag) -> bool {
136 self.iter().any(|(self_tag, _weight)| tag.matches(self...
Rust Walkthroughs
2025-12-03
~9 min read
danclark.io
Archived: primary link replaced with an archive on 2026-09-12T11:22:01.104Z (UTC; replacement date, not snapshot date)
...A simple, ergonomic API to define mocks in Rust
First-class support for streaming and gRPC
A minimal set of "matchers" to match requests to mock responses by method, path, and body
The result of this experiment is mocktail, which I am happy to share with the community, in case...
Project/Tooling Updates
2025-03-19
~2 min read
dev.to
...pattern matching. The branches of a "match" block execute only if the input to the match matches the left hand side and if it does any variables declared within the match store the value in that place of the structure. This is hard to explain but intuitive to write and...
Learn Standard Rust
2020-09-04
~6 min read
alex.draftist.io
...We also need to handle every state without accidentally forgetting one.Pattern matching lets us consider each possibility separately. In Rust, a match must be exhaustive: the compiler rejects it unless every possible case is covered.For example, we have three possible results from parse_port: a valid port, a...
Observations/Thoughts
2026-08-05
~10 min read