philbooth.gitlab.io
...Bom = "foo.txt".parse().unwrap(); match bom { Bom::Null => { // No BOM was detected } Bom::Bocu1 => { // BOCU-1 BOM was detected } Bom::Gb18030 => { // GB 18030 BOM was detected } Bom::Scsu => { // SCSU BOM was detected } Bom::UtfEbcdic => { // UTF-EBCDIC BOM was detected } Bom::Utf1 => { // UTF-1 BOM was detected } Bom::Utf7 => { // UTF...
Crate
v2.0.3
2023-11-13
swatinem.de
...L32, B64
}
impl<'data> ElfHeader<'data> {
pub fn parse(buf: &'data [u8]) -> Option<(Self, &'data [u8])> {
let (e_ident, _rest) = LayoutVerified::<_, ElfIdent>::new_from_prefix(buf)?;
if e_ident.e_mag != *b"\x7fELF" {
return None;
}
match e_ident.e_class {
// 32-bit
1 => {
match e_ident.e_data {
// LE
1...
Rust Walkthroughs
2022-08-10
~11 min read
usethe.computer
...Event) -> Result<(), Box<dyn Error>> {
self.state = match self.state {
ParserState::Between => {
match ev {
Event::Start(e) if e.local_name() == b"wcproduction" =>
ParserState::ProductionNeedAPI,
_ => ParserState::Between,
}
},
ParserState::ProductionNeedAPI => {
match ev {
Event::Start(e) => match e.local_name() {
b"api_st_cde" => ParserState::ReadAPIState,
b"api_cnty_cde" => ParserState::ReadAPICounty...
Observations/Thoughts
2020-10-28
~17 min read
natkr.com
...waker.clone() };
loop {
match fut.poll(&mut context) {
Poll::Ready(out) => return out,
Poll::Pending => waker.sleep_until_awoken(),
}
}
}
Just to be sure.. let's try it out before continuing. To make sure that
our wakeup works, and that we're actually sleeping when we can:
struct ImmediatelyAwoken(bool);
impl...
Rust Walkthroughs
2025-04-16
~10 min read
pramode.in
...enum Color {
Red,
Green,
Blue,
}
fn main() {
let c = Color::Green;
match c {
Color::Red => println!("Red"),
Color::Green => println!("Green"),
}
}
The exhaustive nature of the matching process is an important safety net.
Yaron Minsky’s Ocaml for the masses
has a list “destuttering” example which demonstrates the ease with...
News & Blog Posts
2016-09-06
~27 min read
pker.xyz
...The issue handler checks the current TID against our tracked PID
set (we use the lower 32 bits of bpf_get_current_pid_tgid(),
which is the thread ID, matching what the scheduler tracepoints
use). For buffered writes, the kernel's writeback threads
(kworker) are the ones that actually submit...
Project/Tooling Updates
2026-03-04
~13 min read
lib.rs
...TlsStream<TcpStream>) { // ... } for stream in listener.incoming() { match stream { Ok(stream) => { let acceptor = acceptor.clone(); thread::spawn(move || { let stream = acceptor.accept(stream).unwrap(); handle_client(stream); }); } Err(e) => { /* connection failed */ } } } } Supported features This crate supports the following features out of the box: TLS/SSL client communication TLS/SSL server...
Crate
v0.2.18
2026-02-18
advancedresearch.github.io
...Reaches minimum value when reaching goal
Smooth gradient when getting closer to the goal
Rule agnostic
Easy to maintain
My first idea of how this heuristic should look like,
was something that used sub-expressions matching with the goal.
I was thinking about how difficult this would be to code...
Project Updates
2020-11-25
~5 min read
llogiq.github.io
...Then
the as_slice simply became a match over the three possible values
returning one of the three const references.
Now my iter just became self.as_slice().iter(), which was faster
than Option’s. Sorry if I start to bore you, but
ACHIEVEMENT UNLOCKED! :-)
For the final (and titular...
From the Blogosphere
2015-07-27
~4 min read
edunham.net
...make sure the claws are right.
Match the center front of the underside with the center of Ferris’s front
(both have a blue + on the pattern). Be sure the pieces have their right
sides together and the claws are sandwiched between them.
Match the points marked with red triangles...
News & Blog Posts
2016-05-23
~5 min read
owengage.com
...return true;
}
match current_state {
None => self.clear_cache(),
Some(si) => {
let cur = self.state(*si).clone();
if !self.clear_cache() {
return false;
}
// The unwrap is OK because we just cleared the cache and
// therefore know that the next state pointer won't exceed
// STATE_MAX.
*si = self.restore_state...
Rust Walkthroughs
2021-09-08
~4 min read
jamesmcm.github.io
...lambda_runtime::Context) -> Result<(), HandlerError> {
// Create clients here once since we will use them in all cases
let s3_client = S3Client::new(Region::EuWest1);
let ses_client = SesClient::new(Region::EuWest1);
let mut rt = tokio::runtime::Runtime::new().unwrap();
match e {
// Match on different events here...
}
}
Deployment
Now we are...
Learn More Rust
2020-09-04
~13 min read
edvong.com
...We need the compiler to verify that the context on Rule<Ctx> matches the context on the outer Matcher<Ctx>, preventing users from accidentally passing an RpcCtx rule into an AppCtx builder. Once it crosses this threshold, Ctx has fulfilled its purpose too.Inside the syntax tree (AST). Once those...
Observations/Thoughts
2026-11-25
~17 min read
nnethercote.github.io
...Compiler
The part of the compiler that does declarative macro matching is quite old.
Much of the code predated Rust 1.0, and it was the kind of code that people do
their best to avoid touching. Time for some Type 2
fun.
I made a lot of PRs to...
Observations/Thoughts
2022-04-13
~13 min read
doc.rust-lang.org
pub trait Wake
...loop {
match fut.as_mut().poll(&mut cx) {
Poll::Ready(res) => return res,
Poll::Pending => thread::park(),
}
}
}
block_on(async {
println!("Hi from inside a future!");
});
trait
alloc
Stable since 1.51.0
Version 1.100.0-nightly
manishearth.github.io
...cmp_nan, which disallows things like x == NaN
clone_double_ref, which disallows calling .clone() on double-references (&&T), since that’s a straightforward copy and you probably meant to do something like (*x).clone()
match_same_arms, which checks for identical match arm bodies (strong indication of a typo...
News & Blog Posts
2017-01-24
~4 min read
yodalee.me
...u8) -> Result<(), ()>;
}
bus 會 match load/store 的 addr 並選擇正確的記憶體區塊呼叫對應的 load/store,
實作 Device 的裝置再自行計算扣掉起始位址的位址,存取對應的 Vec<u8>。
下面要提到內部包了 VRAM 的 GPU;或是 Timer 接了三條硬體 IO 線,也是一樣實作 Device trait,讓 bus 把存取的呼叫直接 dispatch 給他們。
bus 的 load 實作大概像是這樣:
fn load(&self, addr: u16) -> Result<u8, ()> {
match addr {
CATRIDGE_START...
Observations/Thoughts
2021-06-23
~4 min read
crates.io
...FluentLanguageLoader = fluent_language_loader!(); loader .load_languages(&Localizations, &[loader.fallback_language().clone()]) .unwrap(); assert_eq!( "Hello \u{2068}Bob 23\u{2069}!", // Compile time check for message id, and the `name` argument, // to ensure it matches what is specified in the `fallback_language`'s // fluent resource file. fl!(loader, "hello...
Crate
v0.10.1
2026-07-23
blog.yoshuawuyts.com
...Pin<&mut Self>) -> Option<F::Output> {
match self.project() {
DoneState::Done(output) => output.take(),
DoneState::Future(_) => None,
}
}
}
impl<F: Future> Future for MaybeDone<F> {
type Output = ();
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
match self.as_mut().project() {
DoneState::Future(future) => match future.poll(cx) {
Poll...
Observations/Thoughts
2026-11-04
~8 min read
villagesql.com
...use villagesql::{InValue, VdfReturn};
fn rot13_impl(args: &[InValue]) -> VdfReturn {
match args.first() {
Some(InValue::String(s)) => VdfReturn::string(rot13(s)),
Some(InValue::Null) | None => VdfReturn::null(),
_ => VdfReturn::error("rot13: expected a STRING argument"),
}
}
fn rot13(s: &str) -> String {
s.chars()
.map(|c| match c {
'a'..='m' | 'A'..='M' => (c...
Rust Walkthroughs
2026-06-10
~4 min read