pub struct Node<T> { /* private fields */ }
Expand description

A node within a particular Arena.

Implementations

Returns a reference to the node data.

Returns a mutable reference to the node data.

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.