docs.rs
...u32) -> u32 { match n { 0 | 1 => 1, _ => fib(n-1).await + fib(n-2).await } } The compiler helpfully tells us that: error[E0733]: recursion in an `async fn` requires boxing --> src/main.rs:1:26 | 1 | async fn fib(n : u32) -> u32 { | ^^^ recursive `async fn` | = note: a recursive `async fn...
Crate
v1.2.0
2026-10-03
ricardoanderegg.com
...usize = if ctx.len() <= arg_cap_group {
// no capture group, use default
0
} else {
ctx.get(arg_cap_group).context("capture group")?
};
// let mut caploc = re.capture_locations();
// re.captures_read(&mut caploc, input_value);
if let Some(cap) = re.captures(input_value) {
match cap.get(cap_group) {
None => empty...
Rust Walkthroughs
2022-05-18
~10 min read
docs.rs
...assert_eq!(queue.pop(), None); // There are Entry API if you want to avoid double hash lookups match queue.entry("Entry"){ Entry::Vacant(entry)=>entry.set_priority(10), Entry::Occupied(_)=>unreachable!(), }; match queue.entry("Entry"){ Entry::Vacant(_)=>unreachable!(), Entry::Occupied(entry)=>{ assert_eq!(entry.get_key(), &"Entry"); assert_eq!(entry...
Crate
v0.4.2
2023-11-15
github.com
...let mut current_op = Op::Plus; let mut current_digit = 0; for d in op_or_digit.into_iter() { match d { OpOrDigit::Op(op) => { current_op = op }, OpOrDigit::Digit(n) => { match current_op { Op::Plus => { current_digit += n }, Op::Minus => { current_digit -= n }, Op::Multiply => { current_digit *= n }, } }, } } assert_eq...
Crate
v0.12.0
2023-11-18
www.halcyon.hr
...There are several different ways to do this - and it all depends on what you want to do.Pattern matching errorsA simple way of figuring out what’s going on is to use pattern matching on the result type.match how_many_bananas(0) {
Ok(number) => println!("You have {} bananas...
News & Blog Posts
2020-06-16
~13 min read
github.com
...examples/matching.rs includes matching.go by Stefan Nilsson, licensed under Creative Commons Attribution 3.0 Unported License. tests/mpsc.rs includes modifications of code from The Rust Programming Language, licensed under the MIT License and the Apache License, Version 2.0. tests/golang.rs is based on code from...
Crate
v0.5.17
2026-09-05
crates.io
...How to get a compatible version of protoc The protoc binary that you use to generate code needs to have a version that exactly matches the version of the protobuf crate you are using. More specifically, if you are using Rust protobuf x.y.z then you need to use...
Crate
v4.36.2-release
2026-09-17
www.hoverbear.org
...num_read])
.unwrap();
if let Ok(rpc) = json::decode::<RemoteProcedureCall<T>>(data) {
match rpc {
RemoteProcedureCall::RequestVote(call) =>
self.handle_request_vote(call, source),
RemoteProcedureCall::AppendEntries(call) =>
self.handle_append_entries(call, source),
}
} else if let Ok(rpr) = json::decode::<RemoteProcedureResponse>(data) {
match rpr {
RemoteProcedureResponse::Accepted { .. } =>
self.handle_accepted(rpr, source...
Blog Posts
2015-02-09
~5 min read
dev.to
...Uuid) -> ApiResponse {
let mut v = userdb.db.lock().unwrap();
let users = &mut *v;
let pos = users.iter().position(|x| x.id.to_string() == id.to_string());
match pos {
Some(p) => {
if v[p].match_password(&user.password) {
match &user.new_password {
Some(passw) => {
v[p].update_password(&passw);
ApiResponse::ok...
Rust Walkthroughs
2020-11-18
~18 min read
docs.rs
...loop { for issue in &page { println!("{}", issue.title); } page = match octocrab .get_page::<models::issues::Issue>(&page.next) .await? { Some(next_page) => next_page, None => break, } } HTTP API The typed API currently doesn't cover all of GitHub's API at this time, and even if it did GitHub is...
Crate
v0.54.9
2026-10-31
relm4.org
...1
2
3
4
5
6
7
8
9
10
11
let component = MyComponent::builder()
// Start the component service with an initial parameter
.launch("Hello world")
// Attach the returned receiver's messages to this closure.
.connect_receiver(move |sender, message| match message {
// Transform and forward the message
Output::HelloThere => {
sender...
Project/Tooling Updates
2022-07-27
~5 min read
ruudvanasseldonk.com
...The implementation is a big match statement. For example, this is the check for an if-else expression:let expr_type = match expr {
Expr::IfThenElse {
condition_span,
condition,
body_then,
body_else,
span_then,
span_else,
..
} => {
self.check_expr(type_bool_condition(), *condition_span, condition)?;
let type_then = self.check...
Observations/Thoughts
2024-07-24
~15 min read
doc.rust-lang.org
...Result<i32, ParseIntError>) {
match result {
Ok(n) => println!("n is {}", n),
Err(e) => println!("Error: {}", e),
}
}
fn main() {
print(multiply("10", "2"));
print(multiply("t", "2"));
}
The try! macro
Before there was ?, the same functionality was achieved with the try! macro. The ? operator is now recommended, but you may still...
Rust by Example
Book
2024-01-01
~1 min read
crates.io
A crate of the gitoxide project dealing with pattern matching
Crate
v0.30.0
2026-11-22
asquera.de
...let res = match req {
ExampleRequest::Get { url: url } => {
match db.get(&url) {
Some(v) => ExampleResponse::Ok { content: v.clone() },
None => ExampleResponse::NotFound,
}
},
ExampleRequest::Post { url: url, content: content } => {
match db.insert(url, content) {
Some(v) => ExampleResponse::Ok { content: v },
None => ExampleResponse::Ok { content: "".into() },
}
}
};
println!("Database: {:?}", *db);
// Return the result...
News & Blog Posts
2017-03-07
~26 min read
rust-lang.github.io
...We will also query the oauth_github table to see if the crates.io username and GitHub username match. If they do match, we will continue with adding this user as an owner. If they don't match, we will return an error containing information about the mismatch and asking...
RFC 3946
RFC
2026-04-07
~28 min read
rustc-dev-guide.rust-lang.org
...Most error annotations need to match with the line of the diagnostic. There are several ways to match the message with the line (see the examples below):
• ~: Associates the error level and message with the current line
• ~^: Associates the error level and message with the previous error annotation line. Each...
Guide to Rustc Development
Book
2024-01-01
~19 min read
rust-lang.github.io
...Unresolved questions
• The behavior specified here should match the behavior of MSVC at least. Does it match the behavior of other C/C++ compilers as well?
• Should it still be safe to borrow fields whose alignment is less than or equal to the specified packing or should all field borrows...
RFC 1399
RFC
2015-12-06
~3 min read
docs.rs
Diff library with semantic cleanup, based on Google's diff-match-patch
Crate
v1.0.11
2026-03-15
lwn.net
...Another improvement to the language's usability is a proposed infix
pattern-matching operator. Rust has some support for pattern matching inside
conditionals, but that can result in having to read the condition in an awkward
order, Triplett explained. For example, this code matches the pattern
Some(x) against the...
Observations/Thoughts
2026-10-28
~12 min read