Strong-typed arena. Simple library for creating complex domain-specific self-referential data structures.
This arena does not use generations approach in a strict sense, but it uses some similar technique for avoiding the ABA effect.
```rust use std::mem::replace; use macroattr2018::macroattr; use componentsarena::{Id, Arena, Component};
macro_attr! {
#[derive(Component!)]
struct Node {
next: Id
struct List {
last: Option
impl List { fn new() -> Self { List { last: None, nodes: Arena::new() } }
fn push(&mut self, data: ()) -> Id<Node> {
let id = self.nodes.insert(|id| (Node { next: id, data }, id));
if let Some(last) = self.last {
self.nodes[id].next = replace(&mut self.nodes[last].next, id);
} else {
self.last = Some(id);
}
id
}
} ```