docs.sru-systems.com
...use argon2::{self, Config}; let password = b"password"; let salt = b"randomsalt"; let config = Config::default(); let hash = argon2::hash_encoded(password, salt, &config).unwrap(); let matches = argon2::verify_encoded(&hash, password).unwrap(); assert!(matches); Create a password hash with custom settings and verify it: use argon2::{self, Config, ThreadMode...
Crate
v3.0.0
2025-07-17
crates.io
Emulate macro-rules pattern matching in procedural macros proc-macro-rules macro_rules -style syntax matching for procedural macros. This crate is work-in-progress, incomplete, and probably buggy! Example: rules!(tokens => { ($finish:ident ($($found:ident)*) # [ $($inner:tt)* ] $($rest:tt)*) => { for f in found { do_something(finish, f, inner, rest...
Crate
v0.4.0
2023-11-07
dev.to
...either match everything, or using combinators: ok(), unwrap_or(), and_then(), etc, etc... I prefer to match and follow strict indentation, so that it is clearer at the end what we are matching for. We use indentation to help understanding the patterns of Ok(_)/Err(_) and Some(_)/None.
Maybe it...
Rust Walkthroughs
2020-12-02
~18 min read
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
doc.rust-lang.org
primitive i128
...i128 is intended to always match __int128 and does not attempt to match _BitInt(128) on platforms without __int128.
primitive
core
Stable since 1.26.0
Version 1.100.0-nightly
doc.rust-lang.org
primitive i128
...i128 is intended to always match __int128 and does not attempt to match _BitInt(128) on platforms without __int128.
primitive
std
Stable since 1.26.0
Version 1.100.0-nightly
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
gtk-rs.org
...crate and its dependencies to match the GNOME 50 SDK gnome_49 Enable all version feature flags of this crate and its dependencies to match the GNOME 49 SDK gnome_48 Enable all version feature flags of this crate and its dependencies to match the GNOME 48 SDK gnome_47...
Crate
v0.11.5
2026-09-20
crates.io
Unicode caseless matching rust-caseless Unicode caseless matching
Crate
v0.2.2
2024-12-30
crates.io
...i32) -> impl Iterator<Item = i32> { match x { 0 => 1..10, #[nested] _ => match x { 1 => vec![5, 10].into_iter(), _ => 0..=x, }, } } See documentation for more details. Supported traits #[enum_derive] implements the supported traits and passes unsupported traits to #[derive] . #[enum_derive] supports many of the standard library traits and...
Crate
v0.8.11
2026-11-21
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