Everyone in the Rust ecosystem eventually runs into "Learn Rust With Entirely Too Many Linked Lists"—and for good reason. Doubly linked lists are notoriously awkward with Rust's ownership rules, usually forcing developers into Rc<RefCell<Node<T>>> (which trades compile-time safety for runtime borrow panics and forfeits Send + Sync) or raw pointers inside unsafe blocks.
While architecting the watch-queue foundation for a low-latency anomaly and threat-anticipation engine in Rust 2024, I needed a doubly linked list that was:
- Strictly safe (
#![forbid(unsafe_code)]) - Thread-safe (
Send + Sync) sotokioandaxumasync workers can share state without friction - Cache-friendly across thousands of evolutionary generations
- Capable of O(1) insertion and O(1) node eviction
Here is how I structured the Arena-Allocated Doubly Linked List and paired it with a Fuzzy Rule-Based Evolutionary Algorithm (FEA)—with zero unsafe blocks and zero compiler warnings.
🔗 Full Source Code (GPL-3.0): ://github.com
1. Arena Allocation Over Pointer Chasing
Instead of allocating individual Node<T> structs scattered across the heap, all nodes live inside a contiguous Vec<Node<T>> arena and reference each other via Option<usize> indices:
#[derive(Debug, Clone)] pub struct Node<T> { pub data: T, pub prev: Option<usize>, pub next: Option<usize>, } #[derive(Debug, Clone, Default)] pub struct DoublyLinkedList<T> { pub head: Option<usize>, pub tail: Option<usize>, pub nodes: Vec<Node<T>>, active_len: usize, } Why This Works So Well in Rust
- Automatic
Send + Sync: Becauseusizeis a plain value type,DoublyLinkedList<T>automatically implementsSendandSyncwheneverTdoes. - O(1) Node Unlinking (
remove_node): Detaching a decayed or evicted node simply rewires its neighbors'usizeindices in constant time without deallocating mid-arena memory. - CPU Cache Locality: Traversing an evolutionary population hits contiguous memory rather than chasing fragmented heap pointers.
2. Cycle-Guarded Safe Mutable Traversal (for_each_mut)
Forward (iter) and reverse (rev_iter) immutable iterators are straightforward to write with Option<usize>. Mutable iteration, however, normally tempts developers into raw pointers (*mut T) because Rust's Iterator trait cannot prove at compile time that arbitrary arena indices don't form a cycle and alias the same element twice.
To keep #![forbid(unsafe_code)] intact, I replaced raw-pointer mutable iteration with a cycle-guarded for_each_mut closure:
pub fn for_each_mut<F>(&mut self, mut f: F) where F: FnMut(&mut T), { let mut current = self.head; let mut visited = 0; let limit = self.active_len; while let Some(idx) = current { if visited >= limit { break; // Guarantees termination even if arena links are corrupted } let node = &mut self.nodes[idx]; current = node.next; f(&mut node.data); visited += 1; } } This satisfies the borrow checker completely, avoids raw pointers, and guarantees loop termination in O(n) steps.
3. Training-Free Fuzzy Rate Adaptation (adapt_rates)
Rather than relying on static hyperparameters or heavy offline neural-network training, the evolutionary loop modulates its mutation rate (pₘ) and crossover rate (pₓ) dynamically at each generation using fuzzy threshold rules over normalized population fitness:
fn adapt_rates(&mut self, avg_fitness: f64) { if avg_fitness > 0.7 { // High fitness: dampen mutation, amplify crossover to exploit promising regions self.mutation_rate = (self.mutation_rate * 0.9).clamp(0.01, 0.97); self.crossover_rate = (self.crossover_rate * 1.1).clamp(0.05, 0.97); } else if avg_fitness < 0.3 { // Low fitness: amplify mutation, dampen crossover to escape local optima self.mutation_rate = (self.mutation_rate * 1.1).clamp(0.01, 0.97); self.crossover_rate = (self.crossover_rate * 0.9).clamp(0.05, 0.97); } } Because the heuristic weights remain explicit and decoupled from backpropagated matrices, the system adapts immediately on live data—and its parameters can be inspected or tuned in real time.
What's Next
This open-source repository forms the data-structure foundation for a larger systems architecture I am building in Rust (tokio / axum) that pairs bounded fuzzy-set forests with evolutionary anomaly anticipation and cold-signature Bloom-filter resurrection.
- Explore the code & unit tests: Fuzzy-Evolutionary_DoublyLinkedList on GitHub
- Systems Design Portfolio & Wiki: ayumi-kiyomizu-systems-design-portfolio
I would love feedback from the Rust community—especially around arena free-list compaction strategies when remove_node runs at high throughput!

