Articles tagged #rust

Futures Nostalgia

Up until recently, hyper was my favorite Rust HTTP framework. It’s low-level, but that gives you a lot of control over what happens.

Here’s what a sample hyper application would look like:

$ cargo new nostalgia Created binary (application) `nostalgia` package
$ cd nostalgia $ cargo add hyper@0.14 --features "http1 tcp server" Updating 'https://github.com/rust-lang/crates.io-index' index Adding hyper v0.14 to dependencies with features: ["http1", "tcp", "server"] $ cargo add tokio@1 --features "full" Updating 'https://github.com/rust-lang/crates.io-index' index Adding tokio v1 to dependencies with features: ["full"]

Request coalescing in async Rust

As the popular saying goes, there are only two hard problems in computer science: caching, off-by-one errors, and getting a Rust job that isn’t cryptocurrency-related.

Today, we’ll discuss caching! Or rather, we’ll discuss… “request coalescing”, or “request deduplication”, or “single-flighting” - there’s many names for that concept, which we’ll get into fairly soon.

A Rust match made in hell

I often write pieces that showcase how well Rust can work for you, and how it can let you build powerful abstractions, and prevents you from making a bunch of mistakes.

If you read something like Some mistakes Rust doesn’t catch in isolation, it could seem as if I had only nice things to say about Rust, and it’s a perfect little fantasy land where nothing ever goes wrong.

Some mistakes Rust doesn't catch

I still get excited about programming languages. But these days, it’s not so much because of what they let me do, but rather what they don’t let me do.

Ultimately, what you can with a programming language is seldom limited by the language itself: there’s nothing you can do in C++ that you can’t do in C, given infinite time.

As long as a language is turing-complete and compiles down to assembly, no matter the interface, it’s the same machine you’re talking to. You’re limited by… what your hardware can do, how much memory it has (and how fast it is), what kind of peripherals are plugged into it, and so on.

Profiling linkers

In the wake of Why is my Rust build so slow?, developers from the mold and lld linkers reached out, wondering why using their linker didn’t make a big difference.

Of course the answer was “there’s just not that much linking to do”, and so any difference between mold and lld was within a second. GNU ld was lagging way behind, at four seconds or so.

One funny way to bundle assets

Cool bear

There’s one thing that bothers me. In part 1, why are we using hyper-staticfile? Couldn’t we just use file:/// URLs?

Well, first off: showing off how easy it is to serve some static files, even in a “scary” language like Rust, is just not something I could pass up.

But also: think about distributing salvage as a tool. Will we want to distribute all those HTML/CSS/JS/font files alongside it?

The rest of the fucking owl

Cool bear

NO! No no no.

What?

Cool bear

WE WERE DONE!

Well… yes! But also no. We still shell out to a bunch of tools:

$ rg 'Command::new' src/commands/mod.rs 126: let variant = if let Ok(output) = run_command(Command::new("wslpath").arg("-m").arg("/")) { src/commands/cavif.rs 29: Command::new("cavif") src/commands/imagemagick.rs 25: Command::new(&self.bin) src/commands/cwebp.rs 25: Command::new("cwebp") src/commands/svgo.rs 25: Command::new("svgo")

Productionizing our poppler build

I was a bit anxious about running our poppler meson build in CI, because it’s the real test, you know? “Works on my machine” only goes so far, things have a tendency to break once you try to make them reproducible.

And I was right to worry… but not for the reasons I thought. As I tried to get everything to build in CI, there was a Pypi maintenance that prevented me from installing meson, and then Sourceforge was acting up.

Go back to the homepage.