pub struct Node<T> { /* private fields */ }
Expand description
A node within a particular Arena
.
Implementations§
source§impl<T> Node<T>
impl<T> Node<T>
sourcepub fn parent(&self) -> Option<NodeId>
pub fn parent(&self) -> Option<NodeId>
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));
sourcepub fn first_child(&self) -> Option<NodeId>
pub fn first_child(&self) -> Option<NodeId>
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);
sourcepub fn last_child(&self) -> Option<NodeId>
pub fn last_child(&self) -> Option<NodeId>
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);
sourcepub fn previous_sibling(&self) -> Option<NodeId>
pub fn previous_sibling(&self) -> Option<NodeId>
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));
sourcepub fn next_sibling(&self) -> Option<NodeId>
pub fn next_sibling(&self) -> Option<NodeId>
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);
sourcepub fn is_removed(&self) -> bool
pub fn is_removed(&self) -> bool
Checks if the node is marked as removed.
§Examples
// arena
// `-- 1
// |-- 1_1
// |-- 1_2 *
// `-- 1_3
assert_eq!(arena[n1_1].next_sibling(), Some(n1_2));
assert_eq!(arena[n1_2].parent(), Some(n1));
assert!(!arena[n1_2].is_removed());
assert_eq!(arena[n1_3].previous_sibling(), Some(n1_2));
n1_2.remove(&mut arena);
// arena
// `-- 1
// |-- 1_1
// `-- 1_3
assert_eq!(arena[n1_1].next_sibling(), Some(n1_3));
assert_eq!(arena[n1_2].parent(), None);
assert!(arena[n1_2].is_removed());
assert_eq!(arena[n1_3].previous_sibling(), Some(n1_1));
Trait Implementations§
source§impl<T: PartialEq> PartialEq for Node<T>
impl<T: PartialEq> PartialEq for Node<T>
impl<T: Eq> Eq for Node<T>
impl<T> StructuralPartialEq for Node<T>
Auto Trait Implementations§
impl<T> Freeze for Node<T>where
T: Freeze,
impl<T> RefUnwindSafe for Node<T>where
T: RefUnwindSafe,
impl<T> Send for Node<T>where
T: Send,
impl<T> Sync for Node<T>where
T: Sync,
impl<T> Unpin for Node<T>where
T: Unpin,
impl<T> UnwindSafe for Node<T>where
T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more