kerkour.com
...Then we can handle a potential error with match.
fn question() -> Result<(), Error> {
let x = // ...
match ultimate_answer(x) {
Ok(_) => // do something
Err(Error::More) => // do something
Err(Error::Less) => // do something
Err(Error::WrongAnswer) => // do something
}
// ...
}
Or, the most common way to handle errors, forward them with ?.
fn question...
Observations/Thoughts
2022-02-09
~4 min read
www.bekk.christmas
...Then we pattern match on the vector as a slice – a view into an array.When the compiler sees a match expression, it matches the value with the list of patterns and stops when encountering the first pattern that matches. Each branch has the form of SomePattern => some_expression(),. For...
Rust Walkthroughs
2022-12-07
~17 min read
akesson.io
...Pin<&mut Self>,
cx: &mut Context<'_>) -> Poll<()> { loop { match *self { Start { who } => { println!("ready…"); *self = AwaitingSleep { … }; } // the .await: poll the child… AwaitingSleep { sleep, who }
=> match sleep.poll(cx) { // …on Pending, return Pending yourself
// return Pending yourself Pending => return Pending, // loop iteration 1
Ready(_) => { // loop iteration 1 println!("hi {who}!"); *self...
Rust Walkthroughs
2026-09-16
~82 min read
bertptrs.nl
...my_print!(match) would not be accepted.
Edition 2024 brings the :tt fragment specifier up-to-date with the new additions to the language,
allowing it to match _- and const expressions as part of an :expr fragment. If you must
maintain the previous behaviour, you can replace :expr with :expr...
Observations/Thoughts
2025-02-26
~17 min read
rust-lang.github.io
...This lint warns when you use print!() with a format string that ends in a newline.
• match_ref_pats: Checks for matches where all arms match a reference, suggesting to remove the reference and deref the matched expression instead. It also checks for if let &foo = bar blocks.
• ptr_arg...
RFC 2476
RFC
2018-06-14
~30 min read
blog.logrocket.com
...Declarative macros provide a match like an interface where on match the macro is replaced with code inside the matched arm.
Creating declarative macros
// use macro_rules! <name of macro>{<Body>}
macro_rules! add{
// macth like arm for macro
($a:expr,$b:expr)=>{
// macro expand to this code
{
// $a and...
Rust Walkthroughs
2021-02-03
~17 min read
pid7.com
...If the needle is matched, the mask marks the position, allowing trailing_zeros / 8 to find the match index with zero
branching. This bitwise technique avoids branch mispredictions by turning conditional control into arithmetic.
Coined in 1996 by Hank Dietz and Randy Fisher at Purdue University, SWAR repurposes general-purpose...
Observations/Thoughts
2026-09-09
~4 min read
www.sea-ql.org
...513] Added the MATCH, -> and ->> operators for SQLite
use sea_query::extension::sqlite::SqliteBinOper;assert_eq!( Query::select() .column(Char::Character) .from(Char::Table) .and_where(Expr::col(Char::Character).binary(SqliteBinOper::Match, Expr::val("test"))) .build(SqliteQueryBuilder), ( r#"SELECT "character" FROM "character" WHERE "character" MATCH ?"#.to_owned(), Values(vec...
Project/Tooling Updates
2023-01-04
~3 min read
iev.ee
...i also added a \p{utf8} class that lets you constrain matches to valid UTF-8. rust's regex crate guarantees that matches only occur on valid UTF-8 boundaries, so how do you do that when your engine operates on raw bytes? you intersect (&) with the language of valid...
Observations/Thoughts
2026-03-11
~12 min read
blog.burntsushi.net
...option-ex-string-findfn main_find() {
let file_name = "foobar.rs";
match find(file_name, '.') {
None => println!("No file extension found."),
Some(i) => println!("File extension: {}", &file_name[i+1..]),
}
}
This code uses pattern
matching to do case
analysis on the Option<usize> returned by the find function. In fact...
Notable Links
2015-05-18
~57 min read
getcode.substack.com
...Let's try evaluating them by writing an interpreter.impl Expr {
fn eval(&self) -> i32 {
match self {
Expr::Lit(i) => *i,
Expr::Neg(r) => -r.eval(),
Expr::Add(r1, r2) => r1.eval() + r2.eval(),
}
}
}Easy enough - we pattern match on Expr and recursively call eval. Calling eval on the example...
Rust Walkthroughs
2023-03-29
~25 min read
wapl.es
...This needs to
be wrapped in a match to be usable by sort_unstable_by in Triangle::sorted_clockwise:
points.sort_unstable_by(|a, b| {
let order = sort_clockwise(*a, *b, center);
match order {
true => Ordering::Greater,
false => Ordering::Less
}
});
Changing to use Ordering
The above code doesn't feel...
Miscellaneous
2020-07-28
~11 min read
immunant.com
...We added some extra sanity checking for global arrays and found real-world examples where the size of an array declaration didn’t match its definition. Aside from that case, it seems that in practice most global declaration types match their definitions. Functions are another matter entirely. We match extern...
News & Blog Posts
2019-12-24
~15 min read
rust-lang.github.io
...These two variants correspond to concrete types for when the key matched something in the map, and when the key didn't, respectively.
If there isn't a match, the user has exactly one option: insert a value using set, which will also insert the guarantor, and destroy the Entry...
RFC 216
RFC
2014-08-28
~7 min read
dygalo.dev
...Now we can handle the rules and compile CSS selectors for further matching against them:
use kuchiki::Selectors;
fn process_css(document: &NodeRef, css: &str) -> Result<(), InlineError> {
// ...
for rule in rules {
let (selector, block) = rule?;
if let Ok(matching_elements) = document.select(selector) {
for el in matching_elements {
todo!()
}
}
}
Ok...
Learn Standard Rust
2020-08-11
~18 min read
xion.io
...let result = results.into_iter().fold(Ok(vec![]), |mut v, r| match r {
Ok(x) => { v.as_mut().map(|v| v.push(x)); v },
Err(e) => Err(e),
});
and in a loop form:
let mut result = Ok(vec![]);
for r in results {
match r {
Ok(x) => result.as_mut().map...
News & Blog Posts
2017-04-11
~5 min read
blog.logrocket.com
...However, a matches the word, which matches words (“at least one word“). So, our string that contains invalid word separators still successfully matches the words rule because words is only matching part of the input.
We can rectify this by changing our rule to parse until the end of the...
News & Blog Posts
2020-06-23
~20 min read
developers.facebook.com
...Then, the app utilizes Rust’s pattern matching feature using the match keyword. To test things out, I add the “tw” as one of my commands to redirect to Twitter. If there are no matches, it simply redirects to Google. Notice, I am not yet using the query string arguments...
News & Blog Posts
2020-06-30
~21 min read
contextgeneric.dev
...While IsNothing is used for absent fields in partial records, we use IsVoid to represent removed or matched variants in partial variants. This ensures that once a variant has been extracted, it cannot be matched again — preserving both soundness and safety in CGP’s type-driven pattern matching.
Once an...
Rust Walkthroughs
2025-07-30
~58 min read
blog.adamchalmers.com
...We can use separated_list1 to match a line, then match and discard a newline, then match a line, then match and discard a newline, etc etc until the end of the file.
use nom::character::complete::line_ending;
/// Parse the whole Advent of Code day 5 text file.
pub...
Rust Walkthroughs
2022-01-12
~16 min read