Articles on Rust
Last updated: 2023/03/09
Top deep-dives on Rust
RISC-V is one of the few (if not the only) open source instruction set architectures, and was created by academics to be viable for education, research, and practical use. In this series of articles, Stephen Marz gives a detailed outline with instruction on creating your own operating system with Rust and RISC-V.
As you sit at your desk, scratching your head thinking about how you could shave a few seconds off of the function you just wrote, you hear a faint whisper in the wind, "premature optimization is the root of all evil". Well if your function takes days to run, it's definitely not premature. In this short article, the author describes the steps taken to optimize a JSON parsing script that originally took "more than a day to run", down to about 15 minutes using some clever shortcuts.
Amos does an extensive coverage of types in Rust.
Sometimes you can fall into a deep rabbit hole when you're exploring how a programming tool works. Well this article by Amos does so in an exceptional way. Amos starts out trying to print JSON in a Linux terminal with colors, and ends up writing a Rust program.
If you start writing an application that somehow ends up being 10,000 or 100,000 lines of code, your earlier mistakes might come back to haunt you. An easy way to help reduce the chances of that is to learn from the mistakes of others! In this extensive series, Aleksey Kladov articulates the importance of an architecture file, highlights how integration and unit tests are implemented in Cargo, describes his approach to testing, brings forth tribal inline attribute knowledge, advises on organization, and promotes fast build times.
What better way to start the new year than with an exploration of some low level programming? In the first article of this series, the author goes through what it takes to print to the command line with assembly and writes a compiler in Rust that produces quines.
A virtual machine is pretty much another computer running inside of your computer's system. One excuse to build them from scratch is to better understand how computers work. Rodrigo Araujo's extensive article was created for just that reason, and Rodrigo does an excellent job of explaining those gnarly bits that leave you scratching your head (like unexplained bitwise operations).
How does one turn the idea of nothing into something physical? Well Alex, you say in your most pedagogic inner voice, isn't that what 0 is? Well dear reader, it's probably up to the individual, but null is one of the more common methods. Piotr Kołaczkowski's article however, focuses on an alternative to null, the Optional or Maybe type. Piotr specifically focuses on the performance impact of using this type, as opposed to primitives, in both Java and Rust.
Aleksey Kladov demonstrates how one can generate source code without using macros in Rust, but with concepts that apply to other programming languages as well.
Raph Levien introduces a new UI framework for Rust that's powered by synchronized trees.
Kevin King walks through rewriting a personal website using Next.js, React, tsx, and mdx, to a full-stack Rust alternative.
- Yew and Axum to build a single-page application with server-side rendering, Hooks, Markdown, and code syntax highlighting
- Tailwind can be used in Rust files
- Overall the Rust full-stack ecosystem has come a long way, but it's still not close to being ideal
Rust's marvelous memory safety system comes at a cost; it's kind of a pain to implement data structures that have circular references. In this exploratory article, Eli Bendersky tries several different approaches for implementing structures that have circular references (like binary search trees).
Raul Jordan explores some of the trickier concepts in Rust that are worth learning when picking up the language.
- "There are two kinds of references in Rust, a shared reference (also known as a borrow), and a mutable reference (also known as an exclusive reference)"
- Implement Deref to make your code cleaner
- Really annoyed by the borrow checker? Use immutable data structures
In Rust, exception safety is defined as "being ready for unwinding". But that isn't the clearest explanation. Arthur Carcano has written an article that essentially explains exception safety in Rust and how it can be achieved, in the context of array initialization.There's plenty of code to show what is being talked about.
"Very often in programming we find ourselves needing access to some context object in many places in our code". In this exploratory article, Tyler Mandry presents a solution for declaring contexts in Rust that can be provided by the compiler.
Tristan Hume presents a demo project for streaming a Linux process to a remote system for execution.
Mahmoud Al-Qudsi discusses the concept of "zero-cost abstractions" in programming, which is the idea that abstractions should not incur any additional runtime cost. The Rust programming language is used as an example of a language that embraces this concept. Mahmoud goes on to implement a semaphore type in Rust.
Jack Huey discusses how "the NLL borrow checker finally got fully enabled by default" in Rust and how it affects you.
Amos shows how to bundle files for a Rust application using a build script. Wow!
How do you solve an issue where real-time calculations are holding up access to your database? In this article, Mike Bush discusses how he was able to resolve it at his company by building a micro-batching scheduler library in Rust.
Amos explores reducing compile times for Rust.
Alex Ilgayev covers three recent incidents involving malicious packages in the Rust and Python ecosystems.
Another article along the lines of APIs, this time Yoshua Wuyts explores how async operations are handled in different languages, as inspiration for coming up with a standard for Rust. Yoshua uses the recent Swift async overaloading amendment as a template for a similar implementation in Rust, and concluding with a number of caveats.
Property based testing is when you test a general property of an output. It's been popularized in Haskell by the QuickTest framework. In this article however, Aleksey Kladov focuses on a specific step for property testing; "how to conveniently enumerate any kind of combinatorial object without using recursion" in Rust.
Chris Hulbert presents a short program for writing generating PNGs in Rust.
Aleksey Kladov implements a cache in Rust and highlights some of the nuances along the way.
I guess today is an async kind of day huh? As Yoshua Wuyts correctly surmises "sometimes we start things but decide midway through that we would prefer to rather not be doing them". How would this kind of functionality be done in Rust? Yoshua's article first distinguishes between tasks and futures, then goes on to explain how cancellation propagation should work for both, how it can be backported, how to reason about structured concurrency, and much more.
Bevy is a game engine written in Rust. In this article, Pascal Hertleif describes Bevy's basic usage philosophy and how you can "type" things using labels.
"Sometimes in Rust you want to design APIs that provide a little bit of flexibility for the user". In this first part article, Armin Ronacher presents how one can do that using the Any type to get around complexities inherent in the traditional method of using generic type parameters.
Tristan Hume explores how different features of twitter would work if the entire service was run on a single, very powerful machine.
- First step is calculating what kind of load needs to be handled, based on real twitter stats
- If that one machine dies, you're screwed
- Pricing data is included for the fantasy system
In the article, Saoirse Shipwreckt talks about the idea of "registers" (using language differently in different circumstances) in programming languages.
- Looks at registers for asynchronous code in Rust
- ^ is missing the iteration and fallibility registers
- Ponders on what good design choices are
Rustaceans pride themselves on the memory safety of Rust. Many a times I've heard them say, "Rust just won't allow you to make mistakes". That might be the case most of the time, but sometimes you have to go into unsafe mode, which suspends some of the stringent memory rules. In this informative article, Micah Lerner covers a paper that outlines "Rudra, a system for finding memory safety bugs in code written with the Rust programming language". Micah briefly describes Rust's memory management system, then dives into the design, implementation, and evaluation of Rudra.
Protty describes the properties of channels and how they are categorized. The author then goes on to talk about their implementation of an Unbounded, Non-Blocking, MPSC (Multi-Producer Single-Consumer) channel.
- "a 'channel' refers to a type of queue generally used in a programming language for passing data from one concurrent task to another with extra amenities"
- Bounded or Unbounded describes whether or not the channel has a maximum capacity of stuff it can have in it which hasn't been dequeued
- "Blocking channels will pause the caller until it can interact with the channel whereas non-blocking channels will return immediately with some sort of error"
Borys Minaiev has written two articles on solving a mostly white jigsaw puzzle with software (Rust).
- Presents a rough plan to solve the problem
- Implements the plan, but finds issues with it
- Attempts to solve the issues and ends by taking up the challenge to the next level
JeanHeyd Meneide explains the implications of GCC optimizing code in a way that can result in undefined behavior.
- "Yodaiken argues in his blog that Undefined behavior being used for optimization is simply a “reading error”"
- This is not the first time the C Language, implementations, or the C Standard came under flak for this kind of optimization
- The issue is signed integers triggering undefined behavior on a left shift
Simon Heath discusses the problem with generics and how it relates to code reuse, in reference to implementation on the Garnet programming language.
- Although generic types aren't complicated to implement by themselves, the complexity comes up when you want to start reasoning about the relationships between types, including types you don't know about yet
- Modules trade off some power for simplicity
- The main practical difference between traits/typeclasses and modules is that with traits the compiler does more of the accounting work for you
Aviram Hassan and Mehul Arora cover how to hook into Go functions using Rust.
Eric Holk presents the new experimental type called dyn* being added in Rust that will give the language more flexibility to support dynamic dispatch for async methods.
- The aim is to be able to support async functions everywhere in Rust, including in trait objects
- A trait object is an opaque value of another type that implements a set of traits
- dyn* should not impose significant costs above what’s already incurred by dyn
"Mononym provides the core type Named, which represents a named value of type T with a unique type N as its name". From my understanding, this allows one to create proofs in Rust that are type safe, enabling one to better implement functional programming methods. In this introductory article, Soares Chen demos how the Mononym library can be used, then goes on to discuss the technical details of its implementation.
In short, Barry Revzin compares the formatting abilities of Rust to those of C++.
- Rust has various ergonomic features that make it easier to format strings
- Rust has multiple different formatting traits
- Implementing static reflection and interpolated literals from Rust, in C++ could lead to good improvements for formatting in the latter
Aleksey Kladov explains how NixOS' directory structure breaks building Rust code with LLVM's dynamic linker.
lcnr presents an unsound issue in Rust where a function can arbitrarily transmute lifetimes, causing a segmentation fault, and explores possible solutions.
Raph Levien explains how the computation of path clipping for piet-gpu (a new compute-centric 2D GPU renderer) was fully transferred to GPU from CPU.
Jeremy Steward explains his process of creating a transducer egg (module) for Scheme. Jeremy was motivated to create the egg because they wanted Scheme to have something similar to Rust's iterator trait.
- Tranducers are a way to apply a composition of functions to each element in a collection
- Creating something like a trait in Scheme is difficult, because Scheme is a dynamic language
- Scheme library authors aren't really helping the idea that lists should only be used in certain circumstances and not all of the time
Predrag Gruevski highlights "how cargo-semver-checks will benefit from the upcoming query optimization API in the Trustfall query engine".
- "Today, cargo-semver-checks is good enough to prevent real-world semver violations, and fast enough to earn a spot in the release pipeline of most crates"
- Checking larger crates is slow though
- Indices are used to speed things up!
Tony Wu discusses a pain point that occurs "when transferring large amounts of data from a software application running on a typical x86 host machine to an FPGA for accelerated computation".
- "Multi-Scalar-Multiplication is one of the major computational bottlenecks at the core of many Zero-Knowledge-Proof systems"
- "Xilinx/AWS provides a Linux-based driver running in kernel space that manages the low-level configuration of the DMA hardware on the FPGA"
- "Using CPU cores to transfer data usually has low latency, however it is very inefficient for large amounts of data and can result in low performance, so we would much rather use a DMA for the task"