No description
  • Rust 39%
  • Zig 36.8%
  • C 23.7%
  • Makefile 0.5%
Find a file
2026-04-04 20:18:06 -07:00
c imit 2026-04-04 20:18:06 -07:00
rust imit 2026-04-04 20:18:06 -07:00
zig imit 2026-04-04 20:18:06 -07:00
.gitignore imit 2026-04-04 20:18:06 -07:00
README.md imit 2026-04-04 20:18:06 -07:00

Doubly Linked List: Rust, C, and Zig

Illustrative implementations of a doubly linked list in three languages, showing how each handles the aliased-mutability problem that makes this data structure famously awkward in Rust.

Rust — unsafe behind a safe API

The Rust version uses raw pointers (*mut Node<T>) inside the implementation, with every unsafe block annotated with the invariant it relies on. The public API is fully safe — callers cannot trigger undefined behavior.

cd rust && cargo run

C — natural habitat

In C, doubly linked lists are straightforward pointer manipulation. No ownership system to negotiate with.

cd c && make && ./ll

Zig — explicit allocators, optional pointers

Zig sits between C and Rust: no borrow checker, but nullable pointer types (?*T) make null handling explicit at compile time, and debug builds include runtime safety checks.

cd zig && zig build run