doc.rust-lang.org
...Code that looked like this:
// Rust 2015
extern crate futures;
use futures::Future;
mod foo {
pub struct Bar;
}
use foo::Bar;
fn my_poll() -> futures::Poll { ... }
enum SomeEnum {
V1(usize),
V2(String),
}
fn func() {
let five = std::sync::Arc::new(5);
use SomeEnum::*;
match ... {
V1(i) => { ... }
V2(s) => { ... }
}
}
will look...
The Rust Edition Guide
Book
2024-01-01
~7 min read
gekkio.fi
...let op = read_op();
match op {
// ...
0xC1 => { // POP BC
cpu.bc = mem_read_u16(cpu.sp);
cpu.sp += 2;
cpu.cycles += 3;
},
0xC5 => { // PUSH BC
cpu.sp -= 2;
mem_write_u16(cpu.sp, cpu.bc);
cpu.cycles += 4;
}
// ...
}
This might seem perfectly fine, but is actually inaccurate if we look...
Blog Posts
2015-01-19
~4 min read
rust-lang-nursery.github.io
...of an array in parallel | [![rayon-badge]][rayon] | [![cat-concurrency-badge]][cat-concurrency] | | Test in parallel if any or all elements of a collection match a given predicate | [![rayon-badge]][rayon] | [![cat-concurrency-badge]][cat-concurrency] | | Search items using given predicate in parallel | [![rayon-badge]][rayon] | [![cat-concurrency-badge]][cat...
The Rust Cookbook
Book
2024-01-01
~1 min read
doc.rust-lang.org
pub fn get_key_value<Q>(&self, k: &Q) -> Option<(&K, &V)>
...The supplied key may be any borrowed form of the map's key type, but Hash and Eq on the borrowed form must match those for the key type.
Examples
use std::collections::HashMap;
use std::hash::{Hash, Hasher};
#[derive(Clone, Copy, Debug)]
struct S {
id: u32,
name: &'static str...
method
std
Stable since 1.40.0
Version 1.100.0-nightly
bheisler.github.io
...On the other
hand, adding or renaming an ingredient could cause the fuzzy-matching to pick a totally different
closest-match than what it did when I wrote the recipe to start with, which I don’t want.
Every ingredient and recipe (and anything else I add to the system...
Rust Walkthroughs
2020-11-25
~12 min read
app.codecrafters.io
...for stream in listener.incoming() {
match stream {
Ok(stream) => {
// handle the connection
}
Err(e) => {
eprintln!("Failed: {}", e);
}
}
}
The TcpStream struct
The iterator returned from TcpListener::incoming yields instances of TcpStream.
Some important methods associated with the TcpStream struct are:
impl TcpStream {
// read reads bytes from the stream
pub fn read...
Miscellaneous
2024-04-24
~3 min read
determinate.systems
...impl Instrumentation { // (continued) pub(crate) fn setup(&self) -> color_eyre::Result<()> { let filter_layer = self.filter_layer()?; let registry = tracing_subscriber::registry() .with(filter_layer) .with(tracing_error::ErrorLayer::default()); // `try_init` called inside `match` since `with` changes the type match self.logger { Logger::Compact => { registry.with(self.fmt_layer...
Rust Walkthroughs
2023-08-09
~14 min read
doc.rust-lang.org
...Scrutinee
A scrutinee is the expression that is matched on in match expressions and similar pattern matching constructs. For example, in match x { A => 1, B => 2 }, the expression x is the scrutinee.
Size
The size of a value has two definitions.
The first is that it is how much...
The Rust Reference
Book
2024-01-01
~9 min read
write.yiransheng.com
...In cases where multiple peers match, the one with the
longest prefix match is selected.
Conversely, for incoming UDP datagrams, after decapsulation, we
obtain an IP packet with a known source address (src).
Given the connected Peer from which this packet originates,
we check if src falls within that peer...
Rust Walkthroughs
2023-12-20
~58 min read
fasterthanli.me
...But also… we need to pattern match again.
Like so:
match (&this.a, &this.b) {
(State::Ok(_), State::Ok(_)) => {
let a = match std::mem::replace(&mut this.a, State::Gone) {
State::Ok(t) => t,
_ => unreachable!(),
};
let b = match std::mem::replace(&mut this.b, State::Gone) {
State::Ok(t...
Rust Walkthroughs
2021-07-28
~70 min read
blog.veeso.dev
...Indeed the amount of frames in the backtrace can be huge (especially when using tokio), and we want to find the last frame that matches one of the modules we are interested in.
So we'll have to provide a list of modules to the allocator, and it will use...
Observations/Thoughts
2025-07-02
~8 min read
docs.rs
...let recording_rules = client.rules().kind(RuleKind::Recording).get().await; assert!(recording_rules.is_ok()); // Retrieve a list of time series that match certain labels sets ("series selectors"). let select1 = Selector::new() .eq("handler", "/api/v1/query"); let select2 = Selector::new() .eq("job", "node") .regex_eq("mode", ".+"); let time_series...
Crate
v0.9.0
2026-05-09
erickt.github.io
...State) -> (Option<usize>, State) {
loop {
state = match state {
State::Enter => {
return_!(Some(0); State::AfterYield0);
}
State::AfterYield0 => {
return_!(Some(1); State::AfterYield1);
}
State::AfterYield1 => {
return_!(Some(2); State::AfterYield2);
}
State::AfterYield2 => {
goto!(State::Exit);
}
State::Exit => {
return_!(None; State::Exit);
}
}
}
}
}
We move the current state into advance, then have this...
News & Blog Posts
2016-02-01
~6 min read
www.fluvio.io
...use fluvio_smartstream::{smartstream, Record};#[smartstream(filter)]pub fn filter_odd(record: &Record) -> bool { // Parse the input bytes as a UTF-8 string, or return false let string_result = std::str::from_utf8(record.value.as_ref()); let string = match string_result { Ok(s) => s, _ => return false, }; // Parse the string...
Project/Tooling Updates
2021-08-04
~6 min read
docs.rs
...The value is scaled to match that suffix if possible. use human_format::Formatter; let mut f = Formatter::new(); f.with_suffix("M"); assert_eq!(f.format(100_000.0), "0.10 M"); If the suffix is not valid for the current Scales , the formatter falls back to automatic selection...
Crate
v1.2.1
2026-01-17
docs.rs
Automata construction and matching using regular expressions. regex-automata This crate exposes a variety of regex engines used by the regex crate. It provides a vast, sprawling and "expert" level API to each regex engine. The regex engines provided by this crate focus heavily on finite automata implementations and specifically...
Crate
v0.4.19
2026-11-19
llogiq.github.io
...² Java’s switch statement is both less powerful than the fully destructuring
pattern matching of Rust’s match and has surprising fallthrough between
case statements (I have my IDE warn on this to mitigate the surprise).
Note that this list is incomplete, and some things don’t completely match...
News & Blog Posts
2016-02-29
~26 min read
trifectatech.org
...Currently rustc cannot generate this instruction, but we plan to add it as an extension of #[loop_match], a feature that I worked on in a previous Project Goal. I wrote about this earlier in Improving state machine code generation . Currently #[loop_match] is only useful when the next state...
Observations/Thoughts
2026-04-15
~12 min read
crates.io
...u64 = match r.payload { j::ResponsePayload::Success(val) => serde_json::from_str(val.get()).unwrap(), j::ResponsePayload::Failure(err) => panic!("unexpected error: {err}"), }; assert_eq!(n, 12345); } Low-level Ethereum JSON-RPC transport abstraction. This crate handles RPC connection and request management. It builds an RpcClient on top of the...
Crate
v2.6.1
2026-11-16
docs.rs
...join("CMakeLists.txt").exists()); let mut builder = cmake::Config::new(lib_source_dir); // Look for -Zsanitizer=address for flag in rustflags::from_env() { if matches!(flag, Flag::Z(z) if z == "sanitizer=address") { builder.define("ENABLE_SANITIZERS", "ON"); builder.define("SANITIZERS", "address"); break; } } builder.build(); } License Licensed under either of...
Crate
v0.1.7
2025-03-03