deaddabe.fr
...Implementing global aliasing
The need is to be able to match both PascalCase and camelCase, while
keeping the field names in snake_case to cope with established Rust naming
conventions. I first tried to add support for multiple deserialize entries
with the following syntax:
#[serde(rename_all(deserialize = "PascalCase", deserialize...
Observations/Thoughts
2021-01-27
~5 min read
kyle.space
...u16) -> u8 { match addr { // RAM (mirrored every 0x0800 bytes) 0x0000..=0x07FF => { let ram_offset = (addr as usize) % self.ram.len(); self.ram[ram_offset] } // PRG-ROM (mirrored to fill all 32 KiB) 0x8000..=0xFFFF => { let rom_len = self.rom.prg_rom.len(); let rom_offset = (addr as usize - 0x8000) % rom...
News & Blog Posts
2019-10-22
~29 min read
uwheel.rs
...if let Some(rewritten) = self.try_rewrite(&plan) {
Ok(Transformed::yes(rewritten))
} else {
Ok(Transformed::no(plan))
}
}
Internally, the rewriter looks for temporal patterns and aggregation functions
that match the stored wheel indices. If there is a match then the target wheel is
queried and the aggregate result gets stored...
Observations/Thoughts
2024-08-21
~4 min read
sjames.github.io
...Sized + ASN1GenType,
{
type Target = T;
fn deref(&self) -> &T {
match self.0 {
AllocatedData::Asn1CodecAllocated(p) => unsafe { &*p as &T },
AllocatedData::RustAllocated(p) => unsafe { &*p as &T },
}
}
}
impl<T> DerefMut for ASNBox<T>
where
T: Sized + ASN1GenType,
{
fn deref_mut(&mut self) -> &mut T {
match self.0 {
AllocatedData::Asn1CodecAllocated(p) => unsafe...
News & Blog Posts
2020-05-12
~18 min read
hugopeters.me
...Plug<B> + Generic1;
}
impl<A> Functor for Option<A> {
fn fmap<B>(&self, f: &dyn Fn(&<Self as Generic1>::I) -> B) -> <Self as Plug<B>>::R {
// Apply the function over the contained value, if there is one
match self {
None => None,
Some(v) => Some(f(v)),
}
}
}
Applicative
This one is...
Rust Walkthroughs
2021-12-08
~5 min read
johns.codes
...match readline {
Ok(line) => {
match SqlQuery::parse_from_raw(line.as_ref()) {
Ok(q) => println!("{q:?}"),
Err(e) => eprintln!("{e:?}"),
}
}
Now we can finally type some stuff and have different things come back.>> select col1 from foo;
(LocatedSpan { offset: 21, line: 1, fragment: "", extra: () }, Select(SelectStatement { tables: ["foo"], fields: ["col1...
Rust Walkthroughs
2023-01-04
~14 min read
smallcultfollowing.com
...In particular, types that implement
Debug will prefer impl I.Another way to express the rule is to say that impls can specialize one
another in two ways:if the types matched by one impl are a subset of the other,
ignoring where clauses altogether;otherwise, if the types matched...
Blog Posts
2016-10-25
~17 min read
gfx-rs.github.io
...We were especially interested in finding projects matching the following criteria:
Open-source: allows us to easily debug issues and add or modify existing macOS window and surface support
Already using Vulkan for rendering: allows us to simply load gfx-portability on macOS in place of a Vulkan driver on...
News & Blog Posts
2018-09-04
~3 min read
mhamza.dev
...Now, imagine you want to call this function from JavaScript, passing in an object that matches the structure of Data:
do_work({
key_id: 'key_id',
name: 'name',
});
Unfortunately, this pattern is not currently possible with wasm-bindgen due to the restrictions it imposes. It requires the object passed to...
Project/Tooling Updates
2023-06-21
~3 min read
www.ralfj.de
...The same also happens with match statements:
let ptr = std::ptr::null::<i32>();
match *ptr { _ => "happy" } // This is fine!
match *ptr { _val => "not happy" } // This is UB.
The scrutinee of a match expression is a place expression, and if the pattern is _ then a value is never constructed.
However, when...
Observations/Thoughts
2024-08-21
~11 min read
jyn.dev
...Enums without pattern matching are very painful to work with and pattern matching without enums has very odd semantics
Result and Iterators are impossible to implement without generics (or duck-typing, which I think of as type-erased generics)
Send/Sync, and the preconditions to println, are impossible to encode...
Observations/Thoughts
2025-08-27
~7 min read
bheisler.github.io
...u64) -> u64 {
match n {
0 => 1,
1 => 1,
n => fibonacci(n-1) + fibonacci(n-2),
}
}
fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("fib 20", |b| b.iter(|| fibonacci(20)));
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
Finally, run this benchmark with cargo bench. You should see output...
News & Blog Posts
2018-01-16
~5 min read
rust-analyzer.github.io
#11461 (first-contribution) filter generics in Extract struct from enum variant.
#11531 (first contribution) make fill_match_arms assist handle #[doc(hidden)] and #[non_exhaustive].
#11535 (first contribution) add install instructions for Kakoune and Helix.
#11524 (first contribution) state that only the latest stable toolchain is officially supported.
#11424 pass...
Project/Tooling Updates
2022-03-02
~1 min read
www.ncameron.org
...The first rename matches, so we rename to x[4](), then we add the two marks: x[4](1, 2). Neither of the later two renames match, so we end up with the resolved name x[4].
Now consider y[2]. In this case the first rename does not match...
News & Blog Posts
2015-11-09
~11 min read
deislabs.io
...Because recursion requires a concrete type that matches that trait bound, everything else in the whole call stack now had to match those specific concrete types. You can get around this with Boxing, but that is noisy and annoying. To be clear: this isn’t so much a problem to...
Observations/Thoughts
2020-12-16
~15 min read
www.jessestuart.ca
...Next up was considering using an enum with all the possible trait implementors, but then I’d have to match the concrete type for every operation which very quickly gets too complex.
The use case involved composing all the implementors of the aforementioned trait to act as a single implementor...
Observations/Thoughts
2025-10-15
~5 min read
rust-lang-nursery.github.io
...The wav feature compiles in only the WAV reader; enable the features matching the formats you need.
Play an audio file
[![rodio-badge]][rodio] [![cat-multimedia-badge]][cat-multimedia]
Playing a notification sound means opening an output device and handing it a decoded source. [rodio][rodio] does both. DeviceSinkBuilder::open...
The Rust Cookbook
Book
2024-01-01
~1 min read
www.5snb.club
...u8) -> u8 {
match x {
b'0'..=b'9' => x - b'0',
b'a'..=b'f' => x + 10 - b'a',
_ => panic!("unknown character"),
}
}
const fn hl_to_u8(h: u8, l: u8) -> u8 {
hex_to_u4(h) << 4 | hex_to_u4(l)
}
impl const constinto::ConstPanickingFrom<&str> for Color {
fn const...
Miscellaneous
2020-09-30
~7 min read
doc.rust-lang.org
...They’re faster than you might think!)
We’ve already covered some other Rust features, such as pattern matching and enums, that are also influenced by the functional style. Because mastering closures and iterators is an important part of writing fast, idiomatic, Rust code, we’ll devote this entire chapter...
The Rust Programming Language
Book
2024-02-01
~1 min read
www.viget.com
...u32,
}
impl Future for MyFuture {
type Output = i32;
fn poll(&mut self, ctx: &Context) -> Poll<Self::Output> {
match self.count {
3 => Poll::Ready(3),
_ => {
self.count += 1;
ctx.waker().wake();
Poll::Pending
}
}
}
}
Let's go over this line by line:
#[derive(Default)] automatically creates a ::default() function for the type...
News & Blog Posts
2019-04-02
~8 min read