zupzup.org
...println!("requests in flight: {}", request_contexts.len());
for ev in &events {
match ev.u64 {
100 => {
match listener.accept() {
Ok((stream, addr)) => {
stream.set_nonblocking(true)?;
println!("new client: {}", addr);
key += 1;
add_interest(epoll_fd, stream.as_raw_fd(), listener_read_event(key))?;
request_contexts.insert(key, RequestContext::new(stream...
Learn More Rust
2020-10-21
~15 min read
rust-analyzer.github.io
...broken code.
#14920 fix edits for convert_named_struct_to_tuple_struct.
#14950 support floating-point intrinsics in const eval.
#14951 fix string pattern matching in mir interpreter.
#14955 remove unnecessary StorageDead.
#14961 fix drop scopes problems in mir.
#14970 detect multiple bindings for one identifier in the same pattern...
Project/Tooling Updates
2023-06-07
~1 min read
blog.sheerluck.dev
...Arc<PathBuf>) {
let mut buf = vec![0u8; 8192];
// Read data from the socket
let n = match socket.read(&mut buf).await {
Ok(0) => return, // client closed immediately
Ok(n) => n,
Err(_) => return,
};
// Parse the request
let request = match parse_request(&buf[..n]) {
Some(req) => req,
None => {
let response = Response::new...
Rust Walkthroughs
2026-06-24
~30 min read
dev.to
...Environment variables are a good place to store such values and they are fairly easy to change.
# main.rs
fn main(){
match std::env::var("CLIENT_ID1") {
Ok(client_id) => println!("Client ID: {}", client_id),
Err(e) => panic!("Couldn't read CLIENT_ID ({})", e),
};
match std::env::var("CLIENT_SECRET1...
Learn More Rust
2020-08-11
~8 min read
rust-analyzer.github.io
#11894 (first contribution) complete pattern args based on type name
#11891 show error message when flycheck fails.
#11915 attempt to heuristically resolve paths in const arguments in IDE layer.
#11953 make extract_module more lazy.
#11896 show path to be created in the unresolved-module fix label.
#11899 skip match...
Project/Tooling Updates
2022-04-13
~1 min read
arthurtw.github.io
...For example, I think Rust’s match syntax:
match key.cmp(&node.key) {
Less => return insert(&mut node.left, key, value),
Greater => return insert(&mut node.right, key, value),
Equal => node.value = value,
}
looks clearer than Nim’s case statement:
case key
of "help", "h": echo usageString
of "ignore-case...
Blog Posts
2015-01-19
~17 min read
tavianator.com
...Bit) -> (Bit, Bit) {
match (a, b) {
(Zero, Zero) => (Zero, Zero),
(Zero, One) => (One, Zero),
(One, Zero) => (One, Zero),
(One, One) => (Zero, One),
}
}
let (s, c) = half_adder(One, One);
println!("One plus One is {:?}, carry the {:?}", s, c);
}
But we want to do all this at compile-time, not runtime...
Observations/Thoughts
2020-10-21
~22 min read
limpet.net
...fn get_color(layout_box: &LayoutBox, name: &str) -> Option<Color> {
match layout_box.box_type {
BlockNode(style) | InlineNode(style) => match style.value(name) {
Some(Value::ColorValue(color)) => Some(color),
_ => None
},
AnonymousBlock => None
}
}
The borders are similar, but instead of a single rectangle we draw
four—one for each edge of...
Blog Posts
2014-11-10
~7 min read
mattrighetti.com
...Form<LoginData>
) -> impl IntoResponse {
// dummy function to get a user
let user = match db::user::get(&app.pg_pool, &username, &password).await {
None => return Redirect::to("/signup").into_response()
Some(user) => user
};
// get/create a refresh token for the user
let refresh_token = match db::refresh_tokens::create(user.id...
Rust Walkthroughs
2025-05-07
~15 min read
blog.pnkfx.org
...As another example, one can step through the the instructions corresponding to
the subcomponents of a match pattern. This way, one might discover which parts
matched and which failed to match, and in what order they were evaluated.
Here is a concrete example of the latter:
1
2
3
4...
Observations/Thoughts
2022-01-12
~18 min read
aibodh.com
...tinyrt/src/state_machine.rsPlace this inside the match armloop { match this { CartTotal::Start { socks, .. } => { match Pin::new(socks).poll(cx) { Poll::Pending => { println!("[cart] Start: socks price not back yet, waiting"); return Poll::Pending; } Poll::Ready(socks_price) => { println!( "[cart] Start -> GotSocks: socks are ${socks_price}" ); let CartTotal::Start...
Rust Walkthroughs
2026-07-01
~22 min read
piware.de
...const char **matches = r_grep("ell", "Hello\nworld\ncan you tell?");
for (const char **m = matches; *m; m++)
printf("matched line: %s\n", *m);
free (matches);
However, I am fairly convinced that the strings inside the returned lists get
leaked. There is no CString::as_mut_ptr(), I can’t...
Rust Walkthroughs
2021-09-08
~6 min read
rust-analyzer.github.io
...pattern_analysis to fix a panic on mismatched types.
#16770 fix panic on float numbers without dots in chain calls (x.1e0).
#16779 skip match diagnostics for partially unknown types.
#16690 use four-space indentation in macro expansion.
#16752 don’t allow destructuring of structs with no public fields.
#16766...
Project/Tooling Updates
2024-03-13
~1 min read
rust-analyzer.github.io
...trait or impl declarations.
#8510 move cursor position when using item movers.
#8536 (first contribution) slightly improve status messages.
#8543 (first contribution) fix "Fill match arms" issue with single-element tuples.
#8545 fix primitive shadowing with inner items.
#8539 do not propose inherent traits in flyimports and import assists.
#8546...
Project/Tooling Updates
2021-04-21
~1 min read
fasterthanli.me
...2
Match arms are patterns
match arms are also patterns, just like if let:
fn print_number(n: Number) {
match n {
Number { odd: true, value } => println!("Odd number: {}", value),
Number { odd: false, value } => println!("Even number: {}", value),
}
}
// this prints the same as before
Exhaustive matches
A match has to be...
Learn Standard Rust
2020-09-09
~31 min read
tech.fpcomplete.com
...Then we pattern match on the Result and return a Pid1Error::ChildPidToBig variant if the conversion fails.
You may be wondering why we used this pattern matching instead of ?. With the right From implementation, ? would work just fine. However, if you want to include additional context with your error, like...
News & Blog Posts
2019-12-03
~22 min read
v5.chriskrycho.com
...let an_example = Example::<String, String, String>::RegularWithGeneric {
field: "Hello".into()
};
match an_example {
Example::RegularWithGeneric { field } => println!("The field is {field}"),
_ => println!("Skipping"),
}
And here’s the same in Swift:3
let an_example = Example<String, String, String>.regularWithGeneric(
RegularWithGeneric(field: "Hello")
)
switch an_example {
case .regularWithGeneric(let wrapped...
Observations/Thoughts
2022-07-13
~2 min read
rust-lang.github.io
...Features:
+ perf Enables all performance related features
+ perf-dfa Enables the use of a lazy DFA for matching
+ perf-inline Enables the use of aggressive inlining inside
match routines
+ perf-literal Enables the use of literal optimizations for
speeding up matches
+ std When enabled, this will cause regex to use...
RFC 3485
RFC
2023-09-09
~5 min read
www.brandons.me
...f32 },
}
impl Shape {
pub fn perimeter(&self) -> f32 {
match self {
Shape::Rectangle { width, height } => width * 2.0 + height * 2.0,
Shape::Triangle { side } => side * 3.0,
Shape::Circle { radius } => radius * 2.0 * std::f32::consts::PI
}
}
pub fn area(&self) -> f32 {
match self {
Shape::Rectangle { width, height } => width * height,
Shape...
Rust Walkthroughs
2022-01-12
~10 min read
www.thecodedmessage.com
...Endian) -> [u8; 4] {
match endianness {
Endian::Little | Endian::Native => { ... }
Endian::Big => { ... }
}
}
fn from_endian_bytes([u8: 4], endianness: Endian) -> Self {
match endianness {
Endian::Little | Endian::Native => { ... }
Endian::Big => { ... }
}
}
}
This would also allow us to implement the concept of “native” byte
order a little differently, and create more names for byte...
Observations/Thoughts
2021-11-24
~19 min read