nbaksalyar.github.io
...fn read(&mut self) {
match self.state {
ClientState::AwaitingHandshake => {
self.read_handshake();
},
_ => {}
}
}
It’s simple - we match on the current value of self.state, and for now we handle only AwaitingHandshake and a match-all case (which is required by the Rust compiler, as the patterns in match should be...
News & Blog Posts
2015-11-16
~32 min read
rust-analyzer.github.io
...substitute variables in config.serverPath.
#13981 don’t run flycheck on startup unless checkOnSave is enabled.
#13966 don’t compute layout if TargetDataLayout is not available.
#13971 improve inference for binary operations more precise.
#13961 don’t generate PartialEq/PartialOrd methods body when types don’t match.
#13984 fix target...
Project/Tooling Updates
2023-01-25
~1 min read
system.joekain.com
...FnMut(&TrapInferior, TrapBreakpoint),
{
- let inferior = inf.pid;
let bp =
- find_breakpoint_matching_inferior_instruction_pointer(&inf)
+ find_breakpoint_matching_inferior_instruction_pointer(inferior)
.expect("Could not find breakpoint");
- match inf.state {
+ match inferior.state {
InferiorState::Running => (),
_ => panic!("Unhandled error in breakpoint::handle"),
}
callback(inferior, bp.target_address);
step_over(inferior...
Observations/Thoughts
2025-08-20
~33 min read
saidvandeklundert.net
...That
Matching enum variants
Using the match keyword, we can do pattern matching on enums. The following function takes the Example enum as an argument:
fn matcher(x: Example) {
match x {
Example::This => println!("We got This."),
Example::That => println!("We got That."),
}
}
We can pass the matcher function a...
Rust Walkthroughs
2021-09-01
~19 min read
hemomorphic.alexblood.net
...Explicit match
The next best way to handle the Result variants, is to match them. This may well be the best solution, depending on the context:
let value = match divisible_by_two(3) {
Ok(value) => value,
Err(err) => {
// do something with the error like default to 0
println!("{err}");
0...
Rust Walkthroughs
2026-05-27
~13 min read
arianfarid.me
...For example, if we represent the code "S" ("G" or "C") as 0101, rotating two bits will still give us 0101.Nucleotide Encoding Let's first look at a simple match expression to see the final schema we have derived. This match expressions encodes each IUPAC nucleotide into a 4...
Rust Walkthroughs
2025-06-25
~7 min read
rust-analyzer.github.io
#12937 (first contribution) implement syntax fix-up for match and for loops.
#13010 actually call rustc from the RUSTC_WRAPPER when run by build scripts (fixes feature detection for anyhow).
#12942 make concat! work with characters.
#12990 improve whitespace insertion in macro-expansion.
#12992 infer byte string pattern as &[u8...
Project/Tooling Updates
2022-08-17
~1 min read
codeandbitters.com
...How do I tell which git commit matches the published crate?
Is there any guarantee that the published crate source matches the git source?
What kinds of best practices exist? Is there room for improvement?
Why do I care about these things? There are a few reasons, but mostly this...
Observations/Thoughts
2021-10-06
~11 min read
www.joshmcguigan.com
...Serializer,
{
let mut serde_state = match Serializer::serialize_struct(
serializer,
"Point",
false as usize + 1 + 1,
) {
serde::export::Ok(val) => val,
serde::export::Err(err) => {
return serde::export::Err(err);
}
};
match SerializeStruct::serialize_field(&mut serde_state, "x", &self.x) {
serde::export::Ok(val) => val,
serde::export::Err(err) => {
return...
News & Blog Posts
2019-11-19
~11 min read
github.com
...Checks for exhaustiveness work identically to matches on structures with named
fields. For instance, if the above match omitted the last case, it would
receive a warning for a non-exhaustive match.
A pattern must include a `..` if it does not match all fields, other than union
fields for which...
RFC 2102
RFC
2017-08-05
~18 min read
doc.rust-lang.org
...No element was found
These cases can either be explicitly handled via match or implicitly with unwrap. Implicit handling will either return the inner element or panic.
Note that it's possible to manually customize panic with expect, but unwrap otherwise leaves us with a less meaningful output than explicit...
Rust by Example
Book
2024-01-01
~1 min read
corrode.dev
...If we use slice pattern matching instead, we’ll only get access to the element if the correct match arm is executed.
match matching_users.as_slice() {
[] => todo!("What to do if no users found!?"),
[existing_user] => { // Safe! Compiler guarantees exactly one element
// No need to index into the vector...
Observations/Thoughts
2025-11-05
~16 min read
ideas.reify.ing
...Pin<&mut _> = this.stream;
match stream.poll_next(cx) {
Poll::Ready(response) => {
match response {
None => Poll::Ready(None), // end of the stream
Some(result) => match result {
Ok(event) => match event {
Event::Open => unreachable!(), // it has been filtered out
Event::Message(message) => {
if message.data == "[DONE]" {
Poll::Ready(None) // end of...
Project/Tooling Updates
2024-04-17
~6 min read
ohadravid.github.io
...poly_match_rs.poly_match_rs.find_close_polygons() takes no arguments (3 given)
v1 - A naive Rust translationWe’ll start with matching the expected API.PyO3 is pretty smart about Python to Rust conversions, so that’s going to be pretty easy:#[pyfunction]
fn find_close_polygons(polygons: Vec...
Rust Walkthroughs
2023-03-29
~17 min read
andidog.de
...Here’s how I could match
State::Failed(String):
$enum_name::$enum_variant(..) => $int_value
Note that this is not a solution because now it won’t match State::Succeeded and State::Timeout anymore (maybe it
used to work earlier), but this article is more about getting to
understand the...
Blog Posts
2016-11-01
~4 min read
academy.fpblock.com
...an uninhabited type (Infallible or a custom enum Never {}), and
an exhaustive match over that type.
We'll implement this using a macro:
macro_rules! absurd {
($x:expr) => {
match $x {}
};
}
This matches the meaning from Haskell: given a value of an uninhabited type, we can produce any type we want...
Miscellaneous
2025-11-19
~21 min read
github.com
...match *self {
AnimationValue::Color(_) => LonghandId::Color,
AnimationValue::Height(_) => LonghandId::Height,
AnimationValue::TransformOrigin(_) => LonghandId::TransformOrigin,
}
}
}
```
This is not sustainable, as the jump table generated by rustc to compile this
huge match expression is larger than 4KB in the final Gecko binary, when this
operation could be a trivial `u16` copy. This...
RFC 2363
RFC
2018-03-11
~4 min read
blog.davimiku.com
...match guardsThe if keyword after the match variable is a match guard. This arm of the match expression is only matched if the match guard is true.
We've introduced a new function, tokenize_float. Time to implement this:
fn tokenize_float(chars: &Vec<char>, curr_idx: &mut usize) -> Result...
Rust Walkthroughs
2024-11-13
~43 min read
rust-analyzer.github.io
#15118 (first contribution) follow raw pointers in autoderef chain when resolving methods with custom receiver.
#15235 (first contribution) don’t insert semicolon when extracting match arm.
#15226 make Expand glob import work on enum imports.
#15211 support GATs in bounds for associated types.
#15223 don’t show unresolved-field diagnostic...
Project/Tooling Updates
2023-07-12
~1 min read
dystroy.org
...while !(maze.is_won() || maze.is_lost()) {
renderer.write(w, &maze)?;
w.flush()?;
let e = event::read();
match e {
Ok(Event::Key(key_event)) => match key_event.into() {
key!(q) | key!(ctrl-c) | key!(ctrl-q) => {
return Ok(());
}
key!(up) => maze.try_move_up(),
key!(right) => maze.try_move_right...
Observations/Thoughts
2022-08-03
~3 min read