components-arena

Crates.iocomponents-arena
lib.rscomponents-arena
version
sourcesrc
created_at2020-08-12 00:52:06.412373
updated_at2024-10-20 07:22:10.383815
descriptionSimple library for creating complex domain-specific self-referential data structures.
homepage
repositoryhttps://github.com/A1-Triard/components-arena
max_upload_size
id275633
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`
size0
Warlock (A1-Triard)

documentation

https://docs.rs/components-arena/

README

maintenance: actively developed

components-arena

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.

Example: circular linked list

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
    }
}
Commit count: 232

cargo fmt