SlotAlloc {
// Allocate a new value. If we have a free slot, increment the generation.
fn alloc(&mut self, value: T) -> Index { ... }
// Set the slot for this index to `None` and push the slot onto `free_list`.
//
// Panics if `index.generation` is not correct.
fn free(&mut self, index: Index) { ... }
// Get a value by an allocated index.
//
// Panics if freed or `index.generation` is not correct.
fn get(&self, index: Index) -> &T { ... }
fn get_mut(&mut self, index: Index) -> &mut T { ... }
}
```
This basically works, no more ABA!
We've built a pointer that will panic on misuse (UAF and ABA)! Cool!
[---------------------generation (32 bits)---------------------]
[------------------------slot (32 bits)------------------------]
---
Pointer problems require Pointer solutions
---
## Rust is really bad at circular references
(A misadventure in linked lists)
---
Let's make the Lua linked list in Rust with regular lifetimes
```rust
// A simple example of a node in a linked list.
struct Node<'a> {
value: String,
next: Cell