iddqd, or the hardest kind of unsafe Rust Oxide engineer Cliff L. Biffle released iddqd, a Rust library for maps where keys are borrowed from values, to solve correctness issues in Oxide's Omicron control plane software. The library uses unsafe Rust code to maintain in-memory indexes of large records like disks and sled inventories, preventing unpredictable malfunctions that are difficult to diagnose. I’m the main author of iddqd https://docs.rs/iddqd , a Rust library for maps named after the Doom cheat code https://doomwiki.org/wiki/Doom cheat codes All Doom engine versions where keys are borrowed from values. At Oxide we use it extensively in Omicron https://github.com/oxidecomputer/omicron , our control plane—the software that sits https://rfd.shared.oxide.computer/rfd/0048 at the heart of every Oxide rack, provisions resources like compute and storage for our customers, and ensures the rack stays up and running over time. iddqd maintains in-memory indexes of the kinds of large records that show up everywhere in a system like that, such as disks https://github.com/oxidecomputer/omicron/blob/2e319eb3b9b9fcffb8cee71cffb9cd13397cb316/sled-agent/config-reconciler/src/internal disks.rs L602-L637 or sled inventories https://github.com/oxidecomputer/omicron/blob/2e319eb3b9b9fcffb8cee71cffb9cd13397cb316/nexus/types/src/inventory.rs L682-L717 . As a result, it must be correct: if it misbehaves, our control plane can malfunction in ways that are unpredictable and hard to diagnose. iddqd consists of a fair amount of unsafe code underneath. There’s been some recent concern https://github.com/oven-sh/bun/issues/30719 over the amount of unsafe code in Rust rewrites, so I thought I’d write about some of the unsafe code in iddqd and how we try to tame it. What problem does iddqd solve? what-problem-does-iddqd-solve With Rust’s standard library maps, keys are stored separately from values. Let’s say you want to store a map of records keyed by an email address. With std::collections::BTreeMap https://doc.rust-lang.org/std/collections/struct.BTreeMap.html , you might write something like: // Email is typically a newtype which validates that the email address is well-formed.// In this example, we alias it to String for simplicity.type Email = String;struct User { name: String, age: u8,}let mut users = BTreeMap::