1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//! # Arena based tree data structure
//!
//! This arena tree structure is using just a single `Vec` and numerical
//! identifiers (indices in the vector) instead of reference counted pointers.
//! This means there is no `RefCell` and mutability is handled in a way
//! much more idiomatic to Rust through unique (&mut) access to the arena. The
//! tree can be sent or shared across threads like a `Vec`. This enables
//! general multiprocessing support like parallel tree traversals.
//!
//! # Features
//!
//! * `std` (default) - Enable standard library support. Disable for `no_std`
//! environments (requires `alloc`).
//! * `macros` (default) - Enable the `tree!` macro for declarative tree
//! construction.
//! * `deser` - Enable `serde` serialization and deserialization for
//! [`Arena`], [`Node`], and [`NodeId`].
//! * `par_iter` - Enable parallel iteration via `Arena::par_iter()` using
//! [rayon](https://docs.rs/rayon).
//!
//! # Node removal and reuse
//!
//! Calling [`NodeId::remove`] does not deallocate the node slot. Instead, it
//! marks the slot for reuse via an internal generation counter (stamp). Future
//! calls to [`Arena::new_node`] may recycle freed slots. Stale [`NodeId`]
//! references are detected through [`NodeId::is_removed`], which compares
//! the ID's stamp against the current slot stamp.
//!
//! # Example usage
//!
//! ```
//! use indextree::Arena;
//!
//! // Create a new arena
//! let arena = &mut Arena::new();
//!
//! // Add some new nodes to the arena
//! let a = arena.new_node(1);
//! let b = arena.new_node(2);
//!
//! // Append b to a
//! a.append(b, arena);
//! assert_eq!(b.ancestors(arena).count(), 2);
//! ```
//!
//! # Error handling
//!
//! Methods that modify the tree come in panicking and checked variants.
//! The checked variants (e.g. [`NodeId::checked_append`]) return a
//! [`Result`] with a [`NodeError`] on failure, while the panicking
//! variants (e.g. [`NodeId::append`]) call `.expect()` internally.
//!
//! ```
//! use indextree::{Arena, NodeError};
//!
//! let mut arena = Arena::new();
//! let root = arena.new_node("root");
//!
//! // Cannot append a node to itself
//! assert!(matches!(
//! root.checked_append(root, &mut arena),
//! Err(NodeError::AppendSelf)
//! ));
//! ```
extern crate alloc;
pub use crate::;
pub use indextree_macros as macros;
// Compile-time assertions that Arena and NodeId are Send + Sync.
const _: = ;
pub
pub
pub