Struct generational_indextree::Node
source · [−]pub struct Node<T> { /* private fields */ }
Expand description
A node within a particular Arena
.
Implementations
Returns the ID of the parent node, unless this node is the root of the tree.
Examples
// arena
// `-- 1
// |-- 1_1
// |-- 1_2
// `-- 1_3
assert_eq!(arena[n1].parent(), None);
assert_eq!(arena[n1_1].parent(), Some(n1));
assert_eq!(arena[n1_2].parent(), Some(n1));
assert_eq!(arena[n1_3].parent(), Some(n1));
Returns the ID of the first child of this node, unless it has no child.
Examples
// arena
// `-- 1
// |-- 1_1
// |-- 1_2
// `-- 1_3
assert_eq!(arena[n1].first_child(), Some(n1_1));
assert_eq!(arena[n1_1].first_child(), None);
assert_eq!(arena[n1_2].first_child(), None);
assert_eq!(arena[n1_3].first_child(), None);
Returns the ID of the last child of this node, unless it has no child.
Examples
// arena
// `-- 1
// |-- 1_1
// |-- 1_2
// `-- 1_3
assert_eq!(arena[n1].last_child(), Some(n1_3));
assert_eq!(arena[n1_1].last_child(), None);
assert_eq!(arena[n1_2].last_child(), None);
assert_eq!(arena[n1_3].last_child(), None);
Returns the ID of the previous sibling of this node, unless it is a first child.
Examples
// arena
// `-- 1
// |-- 1_1
// |-- 1_2
// `-- 1_3
assert_eq!(arena[n1].previous_sibling(), None);
assert_eq!(arena[n1_1].previous_sibling(), None);
assert_eq!(arena[n1_2].previous_sibling(), Some(n1_1));
assert_eq!(arena[n1_3].previous_sibling(), Some(n1_2));
Note that newly created nodes are independent toplevel nodes, and they are not siblings by default.
let mut arena = Arena::new();
let n1 = arena.new_node("1");
let n2 = arena.new_node("2");
// arena
// |-- (implicit)
// | `-- 1
// `-- (implicit)
// `-- 2
assert_eq!(arena[n1].previous_sibling(), None);
assert_eq!(arena[n2].previous_sibling(), None);
n1.insert_after(n2, &mut arena);
// arena
// `-- (implicit)
// |-- 1
// `-- 2
assert_eq!(arena[n1].previous_sibling(), None);
assert_eq!(arena[n2].previous_sibling(), Some(n1));
Returns the ID of the next sibling of this node, unless it is a last child.
Examples
// arena
// `-- 1
// |-- 1_1
// |-- 1_2
// `-- 1_3
assert_eq!(arena[n1].next_sibling(), None);
assert_eq!(arena[n1_1].next_sibling(), Some(n1_2));
assert_eq!(arena[n1_2].next_sibling(), Some(n1_3));
assert_eq!(arena[n1_3].next_sibling(), None);
Note that newly created nodes are independent toplevel nodes, and they are not siblings by default.
let mut arena = Arena::new();
let n1 = arena.new_node("1");
let n2 = arena.new_node("2");
// arena
// |-- (implicit)
// | `-- 1
// `-- (implicit)
// `-- 2
assert_eq!(arena[n1].next_sibling(), None);
assert_eq!(arena[n2].next_sibling(), None);
n1.insert_after(n2, &mut arena);
// arena
// `-- (implicit)
// |-- 1
// `-- 2
assert_eq!(arena[n1].next_sibling(), Some(n2));
assert_eq!(arena[n2].next_sibling(), None);
Trait Implementations
Auto Trait Implementations
impl<T> RefUnwindSafe for Node<T> where
T: RefUnwindSafe,
impl<T> UnwindSafe for Node<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more