rust-lang.github.io
Summary
Enable if and match during const evaluation and make them evaluate lazily. In short, this will allow if x < y { y - x } else { x - y } even though the else branch would emit an overflow error for unsigned types if x < y.
Motivation
Conditions in constants are important for making...
RFC 2342
RFC
2018-01-11
~3 min read
erk.dev
...Is there a Clippy lint to enforce exhaustive structural pattern matching?
The examples they gave were the following:
Bad Case
let Foo { bar, .. } = foo;match bar { Bar::A { a, b, .. } => ..., Bar::B { a, .. } => ...,}
Good Case
let Foo { bar, baz: _ } = foo;match bar { Bar::A { a, b, c: _ } => ..., Bar::B { a...
Rust Walkthroughs
2025-08-27
~13 min read
doc.rust-lang.org
...fn main() {
let names = vec!["Bob", "Frank", "Ferris"];
for name in names.iter() {
match name {
&"Ferris" => println!("There is a rustacean among us!"),
// TODO ^ Try deleting the & and matching just "Ferris"
_ => println!("Hello {}", name),
}
}
println!("names: {:?}", names);
}
• into_iter - This consumes the collection so that on each iteration the exact...
Rust by Example
Book
2024-01-01
~2 min read
rust-lang.github.io
...DefId) -> ParamEnv<'tcx> {
if tcx.describe_def(def_id) match Some(Def::Existential(_))
&& tcx.hir.as_local_node_id(def_id) match Some(node_id)
&& tcx.hir.get(node_id) match hir::map::NodeItem(item)
&& item.node match hir::ItemExistential(ref exist_ty)
&& exist_ty.impl_trait_fn match Some...
RFC 2497
RFC
2018-07-13
~54 min read
thesquareplanet.com
...You may be tempted to
write code like this
let mut v = foo();
match v {
Enum::Bar(ref mut x) => {
x += 1;
},
Enum::Baz(ref mut y) => {
y -= 1;
},
_ => (), // needed to make pattern exhaustive
};
v
But match can make this much nicer:
match foo() {
Enum::Bar(x) => Enum::Bar(x...
Blog Posts
2016-10-25
~8 min read
bal-e.org
...you need to match the input (a, b) against the match arms in foo (“parsing”); then you need to compute the output by filling in meta-variables in the match arm body (“transcribing”). r-a’s mbe/expander/matcher.rs, which implements the parsing step, has a top-level comment...
Rust Walkthroughs
2026-05-06
~10 min read
paulkoerbitz.de
...When we apply `match` to a
dereferenced borrowed pointer, we cannot move because we don't have
ownership. Changing the `match_and_print` function to take a value
would work again.
~~~{.rust}
fn match_and_print(e: MyEnum) {
match e {
MyEnum::X(x) => println!("{}", x),
MyEnum::Y(y) => println!("{}", *y...
Announcements, etc
2014-01-18
~13 min read
owengage.com
...We can match on this to call the appropriate visitor methods. Here is a cut down
version of deserialize_any:
fn deserialize_any<V>(mut self, v: V) -> Result<V::Value>
where
V: de::Visitor<'de>,
{
match self.tag {
Tag::Byte => v.visit_i8(self.de.input.consume_byte()? as...
Rust Walkthroughs
2022-08-10
~7 min read
dev.to
...When both maps build successfully, matching elements is a direct lookup. Matching objects are diffed recursively, missing items are reported as insertions or deletions, and the key is incorporated into the output path: containers[name=api].image instead of containers[1].image. The total time complexity is O(n log...
Rust Walkthroughs
2026-09-23
~5 min read
micahkepe.com
...Dots (.) between field names denote concatenation-- "match this field, then that field":$ cat sample.json | jg 'roommates[0].name'
roommates.[0].name:
"Alice"BashWildcards match any single key (*) or any array index ([*]):$ cat sample.json | jg 'favorite_drinks[*]'
favorite_drinks.[0]:
"coffee"
favorite_drinks.[1]:
"Dr. Pepper"
favorite_drinks.[2...
Project/Tooling Updates
2026-04-01
~13 min read
rust-lang.github.io
Summary
Currently when using an if let statement and an irrefutable pattern (read always match) is used the compiler complains with an E0162: irrefutable if-let pattern. The current state breaks macros who want to accept patterns generically and this RFC proposes changing this error to an error-by-default...
RFC 2086
RFC
2017-07-27
~1 min read
blog.datalust.co
...let index_quote = {
let match_quote = _mm256_cmpeq_epi8(block, _mm256_set1_epi8(b'"' as i8));
let index_quote = _mm256_movemask_epi8(match_quote);
let match_escape = _mm256_cmpeq_epi8(block, _mm256_set1_epi8(b'\\' as i8));
let index_escape = _mm256_movemask_epi8(match_escape);
index_quote | index_escape
};
The...
Learn More Rust
2020-09-09
~20 min read
blog.sylver.dev
...Token) -> bool {
self.tokens.get(self.pos) == Some(&expected)
}
fn expect_identifier(&mut self) -> anyhow::Result<&str> {
self.expect_matching(|t| matches!(t, Token::Identifier(_)))
.map(|t| t.as_identifier().unwrap())
}
fn expect_eq(&mut self, expected: Token) -> anyhow::Result<&Token> {
self.expect_matching(|t| *t == expected)
}
fn expect_matching...
Rust Walkthroughs
2024-11-20
~9 min read
ck.kennt-wayne.de
...let mut result = match results.get_mut(i) {
Some(v) => v,
None => panic!("error! no value!")
};
The return value of get_mut() is just an enum, but in Rust enums may contain additionally a value. This leads to constructs like above. The match keyword introduces a pattern matching construct and...
Blog Posts
2015-01-05
~5 min read
blog.frankel.ch
...The language models it as an enum with generics on each value:
#[derive(Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
pub enum Result<T, E> {
Ok(T),
Err(E),
}
Because Rust manages completeness of matches, matching on Result enforces that you handle both branches:
match fn_that_returns_a_result...
Observations/Thoughts
2024-02-14
~4 min read
www.ntietz.com
...Vec<String>) -> Result<Matches, ParseError> {
let mut args_iter = args.into_iter();
let exec_name = match args_iter.next() {
Some(s) => s,
None => return Err(ParseError::MissingProgramName),
};
Next we setup our storage and populate the defaults with our helper function.
// pub fn parse(&self, args: Vec<String>) -> Result<Matches, ParseError...
Rust Walkthroughs
2024-11-06
~11 min read
ntietz.com
...Vec<String>) -> Result<Matches, ParseError> {
let mut args_iter = args.into_iter();
let exec_name = match args_iter.next() {
Some(s) => s,
None => return Err(ParseError::MissingProgramName),
};
Next we setup our storage and populate the defaults with our helper function.
// pub fn parse(&self, args: Vec<String>) -> Result<Matches, ParseError...
Rust Walkthroughs
2024-11-13
~11 min read
rodrigodd.github.io
...loop {
use Instruction::*;
match self.instructions[self.program_counter] {
// ...
Clear => self.memory[self.pointer] = 0,
}
// ...
}
And every time we parse a ] we check if the previous instructions match the
“clear cell” operation, and replace it by the new instruction.
b']' => {
let curr_address = instructions.len();
match bracket_stack.pop() {
Some...
Observations/Thoughts
2022-10-26
~20 min read
doc.rust-lang.org
...let mut s = String::new();
match process.stdout.unwrap().read_to_string(&mut s) {
Err(why) => panic!("couldn't read wc stdout: {}", why),
Ok(_) => print!("wc responded with:\n{}", s),
}
}
Rust by Example
Book
2024-01-01
~1 min read
blog.sheerluck.dev
...Vec<(usize, String)> = Vec::new();
let mut line_number = 1;
for line in contents.lines() {
let is_match = regex.is_match(line);
let should_include = if invert { !is_match } else { is_match };
if should_include {
results.push((line_number, line.to_string()));
}
line_number += 1;
}
results
}
We are borrowing contents...
Rust Walkthroughs
2026-04-15
~15 min read