Crates.io | components-arena |
lib.rs | components-arena |
version | |
source | src |
created_at | 2020-08-12 00:52:06.412373 |
updated_at | 2024-10-20 07:22:10.383815 |
description | Simple library for creating complex domain-specific self-referential data structures. |
homepage | |
repository | https://github.com/A1-Triard/components-arena |
max_upload_size | |
id | 275633 |
Cargo.toml error: | TOML parse error at line 19, column 1 | 19 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
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.
use std::mem::replace;
use macro_attr_2018::macro_attr;
use components_arena::{Id, Arena, Component};
macro_attr! {
#[derive(Component!)]
struct Node {
next: Id<Node>,
data: (),
}
}
struct List {
last: Option<Id<Node>>,
nodes: Arena<Node>,
}
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
}
}