willcrichton.net
...These mechanisms can ensure that two variadic argument lists share important properties, like the number of format string holes matches the number of printf arguments.
Part of an ongoing series about type-level programming in Rust. Consider reading part one first! All code in this note can be found in...
Learn More Rust
2020-08-11
~6 min read
agourlay.github.io
...usize = match args_iter.next() {
- None => num_cpus::get_physical(),
- Some(count) => count.parse().unwrap(),
- };
+ let batch_size: usize = args_iter.next().unwrap().parse().unwrap();
+
+ let workers: usize = num_cpus::get_physical();
- match password_finder(&zip_path, dictionary_path, workers) {
+ match password_finder(&zip_path, dictionary_path, workers, batch_size...
Observations/Thoughts
2022-10-05
~26 min read
rust.code-maven.com
...Vec<(&str, &str)>) -> surrealdb::Result<()> {
for (name, phone) in data {
let response = db
.query("CREATE entry SET name=$name, phone=$phone")
.bind(("name", name))
.bind(("phone", phone))
.await?;
match response.check() {
Ok(_) => {}
Err(err) => {
eprintln!("Could not add entry: '{}'", err);
return Err(err);
}
};
}
Ok(())
}
SELECT to fetch data
This query...
Miscellaneous
2024-01-17
~6 min read
www.chriskrycho.com
...Rust’s match and Swift’s switch and case fill the same role of pattern matching. I’m curious to see how they differ. Does Swift do matching on arbitrary expressions?
Also, I see where the syntax choices came from in both, and while I slightly prefer Rust’s, I...
News & Blog Posts
2015-10-26
~3 min read
joelmccracken.github.io
...open(filename));
try!(file.write_all(bytes));
Ok(())
}
fn log_time(filename: &'static str) -> io::Result<()> {
let entry = formatted_time_entry();
let bytes = entry.as_bytes();
try!(record_entry_in_log(filename, &bytes));
Ok(())
}
fn main2() {
match log_time("log.txt") {
Ok(..) => println!("File created!"),
Err(e) => println!("Error: {}", e...
From the Blogosphere
2015-07-06
~10 min read
rust-lang.github.io
Summary
Make the count parameter of SliceExt::splitn, StrExt::splitn and corresponding reverse variants mean the maximum number of items returned, instead of the maximum number of times to match the separator.
Motivation
The majority of other languages (see examples below) treat the count parameter as the maximum number of...
RFC 979
RFC
2015-03-15
~2 min read
pliniker.github.io
...When computed gotos and optimized tail calls are unavailable, the fallback standard is to use
switch/match statements. It must be noted that a switch/match compiles to a single computed goto,
but it cannot be used to jump to arbitrary points in a function as with the full Computed...
Observations/Thoughts
2021-09-08
~11 min read
rust-lang.github.io
...Crates scope
The patterns will be evaluated during each API call, and if no match is found the request will be denied. Because it's evaluated every time, a crates scope will allow interacting with matching crates published after token creation.
The check for the crates scope is separate from...
RFC 2947
RFC
2022-11-08
~6 min read
rust-analyzer.github.io
...include! and other eager macros work in expression position.
#8970 duplicate dependencies that have multiple DepKinds.
#8975 use todo!() as placeholder body for generated match arms.
#8983 fix type mismatch caused by macros.
#8986 add "Go to type definition" for struct fields within struct.
#8989 try to fix type inference...
Project/Tooling Updates
2021-06-02
~1 min read
adventures.michaelfbryan.com
...Axes> System<L, A> for Motion {
fn poll(&mut self, inputs: &L, outputs: &mut A) {
match self.control_mode {
ControlMode::Idle => {}
ControlMode::Home(ref mut home) => match home.poll(inputs, outputs) {
Transition::Complete => {
self.control_mode = ControlMode::Idle
}
Transition::Fault(_) => {
// TODO: we should probably do something about this fault...
self...
News & Blog Posts
2019-10-29
~5 min read
blog.rust.careers
...Pattern matching: The filtered variable is created by using pattern
matching to filter out any negative numbers from the input vector.
Collecting into a new vector: The squared variable is created by collecting
the results of the map function into a new vector.
Returning a tuple: The function returns a...
Observations/Thoughts
2024-10-30
~17 min read
arzg.github.io
...35 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Let’s also extract the parsers for each of the match arms in lhs:fn lhs(p: &mut Parser) -> Option<CompletedMarker> {
let cm = match p.peek() {
Some(SyntaxKind::Number) => literal(p),
Some(SyntaxKind::Ident) => variable_ref(p),
Some(SyntaxKind...
Rust Walkthroughs
2020-12-23
~4 min read
rust-lang.github.io
...Making temporary lifetime extension consistent between block expressions and if/else blocks and match arms. This has already been implemented and approved: https://github.com/rust-lang/rust/pull/121346
•
Dropping temporaries in a match scrutinee before the arms are evaluated, rather than after, to prevent deadlocks. This has been...
RFC 3606
RFC
2024-04-02
~5 min read
kamalmarhubi.com
...codemap,
};
visitor.visit_mod(&krate.module, krate.span, 0);
visitor.arg_counts
}
Rust’s pattern matching really shines when working with ASTs. You can get a small glimpse of it here: we match on the FnKind to see if the function is a method, a free function (ItemFn), or a...
News & Blog Posts
2016-06-06
~6 min read
diziet.dreamwidth.org
...In particular, although you can specify a pattern to match the arguments to your macro, the pattern matching system has serious limitations (for example, it has a very hard time with Rust’s generic type parameters). Also, you can’t feed existing pieces of your program to a macro without...
Project/Tooling Updates
2023-02-08
~5 min read
www.sea-ql.org
...DatabaseConnection| { assert!(db.ping().await.is_ok()); db.clone().close().await; assert!(matches!(db.ping().await, Err(DbErr::ConnectionAcquire)));}
#1708 Added TryInsert that does not panic on empty inserts
// now, you can do:let res = Bakery::insert_many(std::iter::empty()) .on_empty_do_nothing() .exec(db) .await;assert!(matches...
Project/Tooling Updates
2023-08-16
~5 min read
doc.rust-lang.org
...A match expression is made up of arms. An arm consists of a pattern to match against, and the code that should be run if the value given to match fits that arm’s pattern. Rust takes the value given to match and looks through each arm’s pattern in...
The Rust Programming Language
Book
2024-02-01
~27 min read
hacks.mozilla.org
...Here’s a more elaborate look at what happens in the pattern-matching phase of our fizzbuzz example:
...
// For pattern matching, we build a tuple, containing
// the remainders for integer division of num by 3 and 5
match (num%3, num%5) {
// When "num" is divisible by 3 AND 5...
Notable Links
2015-05-18
~15 min read
serokell.io
...ADTs usually come in a package with pattern matching.
Pattern matching
Pattern matching is also called “destructuring assignment” in some contexts — usually in languages that don’t have proper sum types, and thus pattern matching essentially boils down to syntactic sugar for extracting fields out of records.
There’s also...
Miscellaneous
2025-01-22
~20 min read
hashrust.com
...let browser = match Browser::new(options) {
Ok(browser) => browser,
Err(e) => {
eprintln!("Failed to create browser: {}", e);
return;
}
};
let tab = match browser.wait_for_initial_tab() {
Ok(tab) => tab,
Err(e) => {
eprintln!("Failed to wait for initial tab: {}", e);
return;
}
};
Nothing much to explain here. Then we navigate to the...
Miscellaneous
2022-01-19
~11 min read