kerkour.com
...errs::Error) -> HttpResponse {
let (status, code) = match &err {
Error::AuthenticationRequired => (StatusCode::UNAUTHORIZED, "UNAUTHORIZED"), // 401
Error::PermissionDenied(_) => (StatusCode::FORBIDDEN, "FORBIDDEN"), // 403
Error::NotFound(_) => (StatusCode::NOT_FOUND, "NOT_FOUND"), // 404
_ => (StatusCode::INTERNAL_SERVER_ERROR, "INTERNAL_SERVER_ERROR"), // 500
};
let message = match &self {
err @ Error::Internal(_) => {
// log the internal error
error!("{err}");
err...
Observations/Thoughts
2026-05-20
~8 min read
doc.rust-lang.org
...The should_panic attribute
The should_panic attribute causes a test to pass only if the [test function][attributes.testing.test] to which the attribute is applied panics.
[!EXAMPLE]
#[test]
#[should_panic(expected = "values don't match")]
fn mytest() {
assert_eq!(1, 2, "values don't match");
}
The should_panic...
The Rust Reference
Book
2024-01-01
~3 min read
doc.rust-lang.org
...Note that we do not perform coercions when matching traits (except for receivers, see the next page). If there is an impl for some type U and T coerces to U, that does not constitute an implementation for T. For example, the following will not type check, even though it...
The Rustonomicon
Book
2024-01-01
~1 min read
www.freecodecamp.org
...f32) -> f32 {
match operator {
'+' => first_number + second_number,
'-' => first_number - second_number,
'/' => first_number / second_number,
'*' | 'X' | 'x' => first_number * second_number,
_ => panic!("Invalid operator used."),
}
}
The match expression works similarly to a switch statement in other languages. The match expression takes a value, and a list of arms. Each...
Rust Walkthroughs
2021-12-01
~27 min read
qouteall.fun
...In that case the match expression outputs a value. That match has two branches. Each branch also output a value.
Because the match target cache.get(&key) indirectly borrows cache mutably. And the second branch Some(v) => {v}'s output indirectly borrow match target. This indirect borrow of cache is...
Rust Walkthroughs
2025-10-29
~64 min read
www.ncameron.org
...We will continue to accept any kind of bracket ((), [], {}) around the pattern, but the kind of bracket must match the use. Whilst new macros are being stabilised, these changes should cause deprecation warnings rather than errors to make adoption of the new macro system easier.
Example, old macros:
macro_rules...
News & Blog Posts
2015-12-14
~6 min read
matklad.github.io
...Option<Walrus>) {
let walrus = match walrus {
Some(it) => it,
None => return,
};
...
}
As in the example above, this often comes up with preconditions: a
function might check precondition inside and “do nothing” if it
doesn’t hold, or it could push the task of precondition checking to
its caller, and enforce...
Observations/Thoughts
2023-11-22
~3 min read
rust-lang.github.io
...Make extern crate match fuzzily
Alternatively, we can have the compiler consider hyphens and underscores as equal while looking up a crate. In other words, the crate flim-flam would match both extern crate flim_flam and extern crate "flim-flam" as flim_flam.
This involves much more magic than...
RFC 940
RFC
2015-03-05
~3 min read
www.fluvio.io
...This meant that we needed a separate filter per pattern we wanted to match on.
However we've added the capability to pass in user inputs at the time of execution. So we can have a single filter covering multiple patterns based on how we use it.
This is an...
Project/Tooling Updates
2021-11-03
~3 min read
rustc-dev-guide.rust-lang.org
...A node is considered to match a filter if all of those strings appear in its label. So, for example:
RUST_DEP_GRAPH_FILTER='-> TypeckTables'
would select the predecessors of all TypeckTables nodes. Usually though you want the TypeckTables node for some particular fn, so you might write:
RUST_DEP...
Guide to Rustc Development
Book
2024-01-01
~3 min read
doc.rust-lang.org
...Result<i32>) {
match result {
Ok(n) => println!("The first doubled is {}", n),
Err(e) => println!("Error: {}", e),
}
}
fn main() {
let numbers = vec!["42", "93", "18"];
let empty = vec![];
let strings = vec!["tofu", "93", "18"];
print(double_first(numbers));
print(double_first(empty));
print(double_first(strings));
}
See also:
Dynamic dispatch...
Rust by Example
Book
2024-01-01
~1 min read
aminediro.com
...u8, buf: &mut Vec<u8>) -> Result<usize> {
loop {
let (done, used) = {
let available = match r.fill_buf() {
// ...
};
match memchr::memchr(delim, available) {
Some(i) => {
buf.extend_from_slice(&available[..=i]);
(true, i + 1)
}
None => {
buf.extend_from_slice(available);
(false, available.len())
}
}
};
r.consume(used);
read += used;
if done || used...
Rust Walkthroughs
2024-01-24
~22 min read
blogs.kde.org
...The mapping of completion match metadata to Kate's format (from fundamentals like the match type, to more complex features like smart grouping) can likely be improved still. Ditto for auto-completion behavior (i.e. defining the circumstances in which the completion popup will kick in automatically, as opposed to...
Project Updates
2015-05-18
~3 min read
blog.aloni.org
...Pin<&mut Self>, _cx: &mut Context) -> Poll<Self::Output> {
match self.fib.state {
State::Halted => {
self.fib.state = State::Running;
Poll::Ready(())
}
State::Running => {
self.fib.state = State::Halted;
Poll::Pending
}
}
}
}
Executor
Our executor keeps a vector of uncompleted futures, where the state of each
future is located on the...
News & Blog Posts
2020-01-28
~3 min read
dev.to
...EnumValue<PhoneType>,
// ...
}
// Match directly - the type carries the known/unknown distinction:
match contact.phone_type {
EnumValue::Known(PhoneType::MOBILE) => { /* ... */ }
EnumValue::Known(PhoneType::HOME) => { /* ... */ }
EnumValue::Known(PhoneType::WORK) => { /* ... */ }
EnumValue::Unknown(v) => { /* v is the raw i32 from the wire */ }
}
// Or compare directly (PartialEq<E> is implemented):
if contact.phone_type == PhoneType...
Project/Tooling Updates
2026-03-25
~13 min read
gfx-rs.github.io
...team ported WebRender over and got Firefox and Servo running on gfx-hal
Our API has settled to be at the lowest level, practically matching Vulkan semantics now, and became completely unsafe. To compensate for this, we have started WebGPU implementation with the idea of it becoming the lowest safe...
News & Blog Posts
2019-01-01
~1 min read
fitzgeraldnick.com
...querying each field of a struct, matching on a variant and querying
each of the matched variant’s children. It is also mechanically implemented
inside #[derive(Term)].
The final querying puzzle piece is a combinator putting the one-layer querying
traversal together with generic query functions into recursive querying
traversal...
News & Blog Posts
2017-08-08
~15 min read
fasterthanli.me
...non-exhaustive patterns: `5u16..=std::u16::MAX` not covered
--> src/lib.rs:17:15
|
17 | match x {
| ^ pattern `5u16..=std::u16::MAX` not covered
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
To deal with that possibility, we could return an...
News & Blog Posts
2020-02-25
~29 min read
www.simonclark.dev
...Vec<u32>,
}
pub fn solve_sudoku(input: &mut Sudoku) -> bool {
match find_first_empty(&input.board) {
None => true,
Some((row, col)) => {
for option in options_for(&input.board, row, col){
let idx = (row * 9 + col) as usize;
input.board[idx] = option;
if solve_sudoku(input) {
return true;
}
input.board[idx...
Observations/Thoughts
2021-04-21
~5 min read
llogiq.github.io
...bad_bit_mask,
cmp_nan,
eq_op,
empty_loop,
match_overlapping_arm,
ineffective_bit_mask,
min_max,
modulo_one,
nonsensical_open_options,
out_of_bounds_indexing,
range_step_by_zero,
unit_cmp and others
Readability – a good many lints suggest readability improvements, such as
approx_constant,
block_in_if_condition...
Notable New Crates & Project Updates
2016-02-01
~3 min read