I Built a Database in Rust With Zero Dependencies (and What the Standard Library Quietly Gave Me)
TL;DR — I built a small database in Rust for a 72-hour hackathon with one rule: no third-party packages allowed. Just the language and nothing else. Here's what I had to write by hand, in plain English, and the surprisingly capable standard-library features that made it possible. Full source and a 5-minute video at the bottom. First, what's a "dependency" — and why does anyone care? When you…
The story describes a Rust developer who built a tiny database called zdb for a hackathon with the rule of using no third-party packages. The database is a simple key-value store that saves data to disk and survives crashes. The developer wrote the entire engine by hand in one Rust file, with an empty dependency list.
To save data, the developer decided on a byte layout consisting of a checksum, key length, value length, key, and value. Rust's standard library includes functions to convert numbers to and from bytes. Writing and loading data only required a dozen lines of code, without relying on serialization libraries.
The developer also implemented a checksum to detect data corruption. CRC-32, a simple algorithm, was used to calculate a small number from the data. The checksum was saved alongside the data, and if the recomputed checksum didn't match the saved one, it indicated corruption. The developer verified that their 15-line implementation matched the internationally-known result for a given input.
To prevent multiple instances of the database from writing to the same file simultaneously, the developer used a lock file. By checking if a file named "LOCK" existed and creating it if it didn't, they ensured only one instance of the database could run at a time. The lock file was deleted when the program exited cleanly.
For handling command-line options, the developer used Rust's standard library to read the user's input and matched it against a few commands (put, get, del, list). A simple loop and match statement were used instead of a specialized library like clap.
Finally, the developer introduced a global "run this once" mechanism using Rust's standard library. This feature set up a value the first time it was accessed, and subsequent accesses would use the cached value. It was a straightforward implementation that eliminated the need for additional libraries like once_cell or lazy_static.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.