215 results for "":
Async fn in trait... not
Async fn in trait… not
I was planning on showing the in-progress async_fn_in_trait
feature in the
context of my website, but it turns out, I can’t!
My website uses two databases: one local SQLite database for content, and a shared Postgres database for user credentials, preferences etc. Migrations are run on startup, and each migration implements one of the following traits:
Position-independent code
In the last article, we found where code was hiding in our samples/hello
executable, by disassembling the whole file and then looking for syscalls.
Later on, we learned how to inspect which memory ranges are mapped for a given PID (process identifier). We saw that memory areas weren’t all equal: they can be readable, writable, and/or executable.
That health is mental
Disclaimer:
Trigger warning: depression, talk of suicide.
It’s been a while since I wrote a mental health piece — but I think it’s important to occasionally stop, take a breather, and think about how we feel.
So.
deep breath
I’m okay, I think? Just a little restless.
A bit of personal context
For those keeping score, I went through major life events in 2023 — a divorce, a move, and the news that I might need a second round of jaw surgery.
Declarative memory management
It feels like an eternity since I’ve started using Rust, and yet I remember vividly what it felt like to bang my head against the borrow checker for the first few times.
I’m definitely not alone in that, and there’s been quite a few articles on the subject! But I want to take some time to present the borrow checker from the perspective of its benefits, rather than as an opponent to fend with.
All color is best-effort
I do not come to you with answers today, but rather some observations and a lot of questions.
The weird glitch
Recently I was editing some video and I noticed this:
Not what the finger is pointing at — the dots.
Here are the separate layers this image is made up of: the background is a stock image I’ve licensed from Envato Elements:
Because I use it as a background image, I’ve cranked down the exposition in the Color tab:
Day 10 (Advent of Code 2022)
Onwards! To the day 10 puzzle.
I don’t see a way to make part 1 especially fun — so let’s just get to it.
Parsing
As usual, let’s reach for the nom crate…
$ cargo add nom@7
(cut)
…to parse the input into nicely-organized Rust data structures:
// in `src/main.rs`
use nom::{
branch::alt,
bytes::complete::tag,
combinator::{map, value},
sequence::preceded,
IResult,
};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
enum Instruction {
Noop,
Addx(i32),
}
impl Instruction {
fn parse(i: &str) -> IResult<&str, Self> {
let noop = tag("noop");
let addx = preceded(tag("addx "), nom::character::complete::i32);
alt((value(Self::Noop, noop), map(addx, Self::Addx)))(i)
}
fn cycles(self) -> u32 {
match self {
Self::Noop => 1,
Self::Addx(_) => 2,
}
}
}
Day 1 (Advent of Code 2022)
Two years ago, I did part of Advent of Code 2020 using the Rust language. It was a lot of fun, so let’s try it again!
The problem statement
Our input looks something like this:
1000
2000
3000
4000
5000
6000
7000
8000
9000
10000
Each group of lines separated by an empty line is a list of food items an elf is carrying: each line corresponds to the number of calories in that food.
The case for sans-io
The most popular option to decompress ZIP files from the Rust programming language is a crate simply named zip — At the time of this writing, it has 48 million downloads. It’s fully-featured, supporting various compression methods, encryption, and even supports writing zip files.
However, that’s not the crate everyone uses to read ZIP files. Some applications benefit from using asynchronous I/O, especially if they decompress archives that they download from the network.
Between libcore and libstd
You’re still here! Fantastic.
I have good news, and bad news. The good news is, we’re actually going to make an executable packer now!
Hurray!
I know right? No lie, we’re actually really going to start working on the final product from this point onwards.
What uhhh what about the previous fourteen parts?
Ah, yes, the previous fourteen parts. Well, we had fun, didn’t we? And we learned a lot about ELF, how it’s basically a database format that different tools look at in different ways, how it’s mapped in memory (more or less), what we really need to set up before starting up another executable, all that good stuff.
More devops than I bargained for
Background
I recently had a bit of impromptu disaster recovery, and it gave me a hunger for more! More downtime! More kubernetes manifest! More DNS! Ahhhh!
The plan was really simple. I love dedicated Hetzner servers with all my heart but they are not very fungible.
You have to wait entire minutes for a new dedicated server to be provisioned. Sometimes you pay a setup fee, et cetera. And at some point to server static websites and serve as a K3S server, it’s simply just too big, and approximately twice the price that I should pay.