The Rust language has incrementally grown a set of patterns to support control-flow effects including error handling, iteration, and asynchronous I/O. In The registers of Rust, boats lays out four aspects of this pattern shared by Rust’s three effects. Today these effects are typically used in isolation, or at most combined in bespoke ways, but the Rust project has been working on ways to…
Recursive descent parsers are attractive for their simplicity. A collection of functions, one for each part of your language, looks at the next token to decide what to parse next. The structure and control flow of the program matches the structure of the grammar, so you can write a parser by hand in your favorite language and use familiar tools for testing and debugging.
Google has published a document on Rust and C++ interoperability in the context of Chromium. It describes their criteria for the experience of calling C++ from Rust — minimal use of unsafe, no boilerplate beyond existing C++ declarations, and broad support for existing Chromium types.
I’ve just published the dioptre crate, the newest addition to Driveyard. Dioptre is a lightweight proc-macro for struct field reflection. The subject of this post is a trick built on top of this functionality—Cell field projection, going from Cell<Struct> to Cell<Field>.
Arrays are a natural way to work with collections of objects. They have relatively effective cache utilization, they make iteration and random access easy, and they tend to have good language support. In Rust, arrays lay out each individual object’s fields together in memory, as an “array of structs:”
I’ve been exploring various ways to write parsers. For a long time, I’ve used hand-written recursive descent for its straightforwardness, flexibility, and performance. There is another way—parser generators like Menhir, LALRPOP, or the venerable Bison use the bottom-up LR algorithm.