llogiq.github.io
...enum variants, you can also use match, but keep it simple: Only match one thing, and avoid more complex things like guard clauses:
// Don't nest patterns in match arms
match err_opt_val {
Some(Err(e)) => panic!("{e}"),
_ => (),
}
// instead, nest `match` expressions
match err_opt_val {
Some(err_val...
Observations/Thoughts
2024-04-03
~16 min read
pythonspeed.com
...def assert_matches(counts1, counts2):
"""Match A to Z counts."""
for character in 'abcdefghijklmnopqrstuvwxyz':
assert counts1[character] == counts2[character]
assert_matches(
frequency_1(TEXT),
frequency_3(TEXT)
)
Our new implementation is even faster:
Code
Elapsed microseconds
frequency_2(TEXT)
25,965.5
frequency_3(TEXT)
19,443.5
The Practice...
Observations/Thoughts
2025-07-09
~14 min read
thefuntastic.com
...This is what the match construct is all about: match item_option { Some(item) => { //Do something with resource println!("{}", item); } None => {}};It's called pattern matching and it's a switch statement, but for types. Here the Some branch is the only code path with a valid reference to item...
Observations/Thoughts
2020-10-28
~18 min read
rreverser.com
...bool> MyEnum<AllowB> {
fn is_a(&self) -> bool {
match *self {
MyEnum::A => true,
_ => false,
}
}
}
impl MyEnum<true> {
// this won't be allowed on MyEnum<false>, giving a helpful compile-time error
fn is_b(&self) -> bool {
match *self {
MyEnum::B => true,
_ => false,
}
}
}
The first thing that comes to mind is...
News & Blog Posts
2018-01-02
~5 min read
pitsidianak.is
...Instruction: {instruction:?}")
}};
}
match op {
Op::ORR => {
// Bitwise OR
// This instruction performs a bitwise (inclusive) OR of a register value and an
// immediate value, and writes the result to the destination register.
let target = match instruction.operands()[0] {
bad64::Operand::Reg {
ref reg,
arrspec: None,
} => *self.reg_to_var(reg, true...
Observations/Thoughts
2025-08-27
~10 min read
www.lpalmieri.com
...Expected range of matching incoming requests: == 1
Number of matched incoming requests: 0
'
Why is that?
Let's add a dbg! statement to our matcher to inspect the incoming request:
//! src/email_client.rs
// [...]
#[cfg(test)]
mod tests {
// [...]
impl wiremock::Match for SendEmailBodyMatcher {
fn matches(&self, request: &Request) -> bool {
// [...]
if...
Rust Walkthroughs
2021-01-20
~41 min read
blog.warp.dev
Archived: primary link replaced with an archive on 2026-09-12T11:34:45.562Z (UTC; replacement date, not snapshot date)
...SplitDirection,
) -> bool {
match self {
PaneNode::Leaf(session) => {
if *session == old_session {
*self = PaneNode::Branch(PaneBranch::new(old_session, new_session, direction));
true
} else {
false
}
}
PaneNode::Branch(branch) => branch.split(old_session, new_session, direction),
}
}
fn remove(&mut self, session_id: EntityId) -> bool {
match self {
// Leaves can only be removed from...
Rust Walkthroughs
2022-01-26
~11 min read
rust-gcc.github.io
...Zhi Heng’s work is allowing us to handle some
complex pattern matches present in core, which the compiler would
previously ignore - while Ryutaro’s contributions are adding more
complex warning checkers while removing previous false positives. Thanks
to them, the compiler is getting more correct, and gets closer and...
Project/Tooling Updates
2025-08-06
~11 min read
arzg.github.io
...How is the parser meant to manage expected_kinds if it can’t know which arm of the match is being run and which ones have been tried before? We’ll have to convert all these matches to if else chains that use Parser::at.To ensure we don’t...
Rust Walkthroughs
2020-12-23
~30 min read
arzg.github.io
...First, we’ll determine which particular operator we’re looking at:pub(super) fn expr(p: &mut Parser) {
match p.peek() {
Some(SyntaxKind::Number) | Some(SyntaxKind::Ident) => p.bump(),
_ => {}
}
let op = match p.peek() {
Some(SyntaxKind::Plus) => Op::Add,
Some(SyntaxKind::Minus) => Op::Sub,
Some(SyntaxKind::Star) => Op::Mul,
Some...
Rust Walkthroughs
2020-11-18
~27 min read
arzg.github.io
Archived: primary link replaced with an archive on 2026-09-12T11:26:22.428Z (UTC; replacement date, not snapshot date)
...We should also define a proper format for displaying Vals so we can customise how they appear:// crates/eldiro/src/val.rs
use std::fmt;
// snip
impl fmt::Display for Val {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Number(n) => write!(f, "{}", n),
Self::Unit...
Learn More Rust
2020-10-07
~13 min read
docs.rs
...this is the generic case when we don't know about the input BufRead. // when the input is a &str or a &[u8], we don't actually need to use another // buffer, we could directly call `reader.read_event()` match reader.read_event_into(&mut buf) { Err(e) => panic!("Error...
Crate
v0.42.0
2026-08-22
vincents.dev
...std::num::ParseIntError) -> Self {
DemoError::ParseErr(error)
}
}
impl Error for DemoError {}
impl Display for DemoError {
fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> {
match self {
DemoError::ParseErr(error) => write!(
f,
"error parsing with {}", error.to_string()
),
}
}
}
fn my_function() -> Result<(), DemoError> {
let first_input = "3^";
let my_number...
Rust Walkthroughs
2025-12-31
~9 min read
vishpat.github.io
...Rust's rich programming constructs such as enum, pattern matching, and error handling make it easy and a joy to implement this bare-bone interpreter.
Pre-requistes
To make the most out of this project, it is expected that the user is aware of the following Computer Science concepts
Lists...
Observations/Thoughts
2022-05-11
~2 min read
docs.rs
...ListTablesInput = Default::default(); match client.list_tables(list_tables_input).await { Ok(output) => match output.table_names { Some(table_name_list) => { println!("Tables in database:"); for table_name in table_name_list { println!("{}", table_name); } } None => println!("No tables in database!"), }, Err(error) => { println!("Error: {:?}", error); } } } Usage with rustls If...
Crate
v0.48.0
2022-04-25
rust-analyzer.github.io
Rust toolchains newer than 2022-07-29 contain a proc macro server that should be compatible with macros built by the matching compiler.
Since today’s release, the server is automatically detected by and used rust-analyzer.
This means that, from now on, proc macros will keep working when the...
Project/Tooling Updates
2022-08-03
~1 min read
danube-docs.dev-state.com
Archived: primary link replaced with an archive on 2026-09-12T11:22:08.820Z (UTC; replacement date, not snapshot date)
...Pattern
Matches
"payment"
Exact match only
"ship*"
"shipping", "shipment", etc.
"eu-west-?"
"eu-west-1", "eu-west-2", etc.
"*"
Everything (same as no filter)
Glob matching is implemented with an iterative backtracking algorithm (simple_glob) that handles * and ? without regex overhead.
If a message's routing key matches no consumer...
Project/Tooling Updates
2026-04-22
~8 min read
timryan.org
...But we
lack one important aspect of Rust’s pattern matching capabilities: its
requirement that all match arms must be “exhaustive” (that is, there are no
unhandled cases).
If we matched against the FrontendMessage enum type, but we only handled the
Init and ButtonState variants, our program would fail at...
News & Blog Posts
2019-01-29
~9 min read
docs.rs
...The API version for the given message matching the version specified in the request header must be provided. use bytes::BytesMut; use kafka_protocol::messages::MetadataRequest; use kafka_protocol::protocol::Encodable; let mut bytes = BytesMut::new(); let request = MetadataRequest::default(); request.encode(&mut bytes, 12).unwrap(); Deserialization Messages can be...
Crate
v0.18.0
2026-08-20