codigolinea.com
...pedido registrado"); self.queue.push(Command::Pending(dish)); } fn serve_next(&mut self) { let cmd = match self.queue.pop() { Some(c) => c, None => { println!("Camarero: no hay pedidos en cola"); return; } }; match cmd { Command::Pending(dish) => { println!("Chef: preparando {} para la mesa {}", dish.name, dish.table); self.history.push(Command...
Rust Walkthroughs
2026-01-14
~24 min read
kentaromiura.wordpress.com
...type `std::collections::hash::map::HashMap<collections::string::String, collections::vec::Vec<&’callback mut for<‘r> core::ops::FnMut(&’r mut std::collections::hash::map::HashMap<collections::string::String, T>) + ‘callback>>` does not implement any method in scope named `find_mut`
…/RustyEmitter/src/lib.rs:40 match self.events.find...
Blog Posts
2015-01-12
~4 min read
siciarz.net
...The tag! macro matches the exact characters given. alt! tries to match
any of sub-parsers separated by |, returning the result of the first one
that matches. (Note: we're leaving out other HTTP methods for simplicity.)
$ cargo run
Done([32, 47, 32, 72, 84, 84, 80, 47, 49, 46...
24 Days of Rust
2016-12-13
~4 min read
blakesmith.me
...Because of Rust’s amazing exhaustive pattern matching, it’s safe to add more variants in the future and ensure all cases are handled.
The code intention is much more readable, more self documenting, and easier to grok.
Consider this function signature, with a boolean to indicate why the block...
News & Blog Posts
2019-05-14
~1 min read
dgroshev.com
...mpsc::Receiver<
oneshot::Sender<(RequestId, oneshot::Receiver<Response>)>,
>,
) {
loop {
tokio::select! {
usb_response = usb_rx.recv() => match usb_response {
Some((request_id, response)) =>
dispatcher.handle_usb_rx(request_id, response).await,
None => break
},
request = registration_requests.recv() => match request {
Some(reply_to) => dispatcher.register(reply_to).await,
None => break
}
}
}
}
Points...
Observations/Thoughts
2024-05-15
~5 min read
matthewkmayer.github.io
...let mut connbuilder = SslConnectorBuilder::new(SslMethod::tls()).unwrap();
// https://www.postgresql.org/docs/current/static/libpq-ssl.html describes the modes
match dbssl.to_lowercase().as_ref() {
"require" | "prefer" | "allow" => connbuilder.set_verify(postgres::tls::openssl::openssl::ssl::SSL_VERIFY_NONE),
_ => (), // by default we verify certs: it's like either...
News & Blog Posts
2018-09-18
~3 min read
ferrous-systems.com
...fill in the match statement below */
/* to make this code compile */
let noise = match animal {
/* Cow and Bull */ => {
"moo".to_string()
}
/* Chicken */ => {
"cluck, cluck!".to_string()
}
/* Dog */ => {
format!("woof, woof! I am {}!", name)
}
/* Worm– or all silent animals?*/ => {
"-- (silence)".to_string()
}
};
/* Bonus task: Give Dogs named Lassie */
/* a different output...
Observations/Thoughts
2021-05-05
~5 min read
dev.to
...String,
}
Enter fullscreen mode
Exit fullscreen mode
Now we know we have to match that same error code. Let's find in src/routes/user.rs when we insert a new user:
match user_coll.insert_one(document.to_owned(), None) {
Ok(inserted) => {
match inserted.inserted_id {
Some(id) => { ...},
None...
Rust Walkthroughs
2020-12-23
~12 min read
steveklabnik.com
...At their core, declarative macros allow you to write something similar to a Rust match statement:
match x {
4 => println!("four!"),
5 => println!("five!"),
_ => println!("something else"),
}
With match, x’s structure and value will be evaluated, and the right arm will execute based on what matches. So if x...
News & Blog Posts
2017-01-31
~12 min read
dev.to
...DO NOT USE THIS CODE IN PRODUCTION
let url = match json
.get(0)
.unwrap()
.get("data")
.unwrap()
.get("children")
.unwrap()
.get(0)
.unwrap()
.get("data")
.unwrap()
.get("url")
{
// Parse the youtube url from the string
// "https://www.youtube.com/playlist?list=PLf3u8NhoEikhTC5radGrmmqdkOK-xMDoZ"
// after trimming `"`
Some(url) => match url::Url...
Learn More Rust
2020-08-11
~8 min read
rust-lang.github.io
...To reduce risk of tools in the ecosystem unintentionally matching pre-releases (despite them still needing an opt-in), it might be reasonable for the semver package to offer this new matching behavior under a different name (e.g. VersionReq::matches_prerelease in contrast to the existing VersionReq::matches) (also...
RFC 3493
RFC
2023-09-20
~9 min read
tweedegolf.nl
...Next, there is an operation to turn this SIMD mask vector into an integer, resulting in:0b0111
Finally the .trailing_ones method can be used to count how many elements matched before the first one that didn't. For our example it returns 3, and indeed there are 3 matching...
Observations/Thoughts
2025-05-28
~4 min read
smallcultfollowing.com
...with Thin Traits, you write virtual methods
whereas with Extensible Enums, you write match statements – and I
think match statements are far more common in Rust today.Still, Thin Traits will be a very good fit for various use cases.
They are a good fit for Servo, for example, where...
News & Blog Posts
2015-10-12
~15 min read
codeandbitters.com
...let value = rand::thread_rng().gen();
Self { value }
}
}
Match Ergonomics pattern changes §
Lint: rust-2024-incompatible-pat
Rust edition guide: Match ergonomics reservations
I found this change tricky. I was starting off at a disadvantage, because I didn't know what "match ergonomics" or "binding mode" meant. So the warnings...
Observations/Thoughts
2025-02-12
~18 min read
zupzup.org
...i32,
) -> Result<Vec<Bytes>> {
let https = HttpsConnector::new()?;
let client = Client::builder().build::<_, hyper::Body>(https);
let group = config.group.as_ref();
let user = config.user.as_ref();
let uri = match group {
Some(v) => format!(
"https://gitlab.com/api/v4/groups/{}/{}?per_page={}",
v, domain, per_page
),
None => match user...
News & Blog Posts
2019-11-26
~10 min read
doc.rust-lang.org
...Storing Matching Lines
To finish this function, we need a way to store the matching lines that we want to return. For that, we can make a mutable vector before the for loop and call the push method to store a line in the vector. After the for loop, we...
The Rust Programming Language
Book
2024-02-01
~6 min read
phildawes.net
...uint,
callback: &mut |Match|) {
...
}
complete_from_file("foo", "myfile.rs", 3, |match| {
// do something with each match
});
This means the whole search happens regardless of whether you just want the first match. The main reason for doing this is because iterators are somewhat less easy to write for my brain...
Community Updates
2014-05-17
~5 min read
dimforge.com
...shape-matching, constraints,
and the Finite Elements Method (FEM).
Shape-matching
Main reference: Meshless deformations based on shape matching (Müller, et al.)
Shape-matching is the simplest approach that only needs the soft-body mass points to work (no need for edges or cells).
It is good for sets of...
Observations/Thoughts
2026-09-30
~18 min read
xnacly.me
...Rust makes this enjoyable via the matches! macro and the patterns the
match statement accepts. For instance, checking if the current character is
a valid sqlite number can be done by a simple matches! macro invocation:RUST 1/// Specifically matches https://www.sqlite.org/syntax/numeric-literal.html
2fn is...
Rust Walkthroughs
2024-11-06
~18 min read
www.huy.rocks
...to get the current token
is_match(): to check if the current token matched the expected type or not
advance(): to consume the current token and move on to the next
These methods are not exclusive to a recursive descent parser, but they’re very helpful, as they keep the...
Rust Walkthroughs
2022-05-11
~6 min read