[−][src]Struct indextree::Node
A node within a particular Arena
.
Implementations
impl<T> Node<T>
[src]
pub fn get(&self) -> &T
[src]
Returns a reference to the node data.
pub fn get_mut(&mut self) -> &mut T
[src]
Returns a mutable reference to the node data.
pub fn parent(&self) -> Option<NodeId>
[src]
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));
pub fn first_child(&self) -> Option<NodeId>
[src]
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);
pub fn last_child(&self) -> Option<NodeId>
[src]
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);
pub fn previous_sibling(&self) -> Option<NodeId>
[src]
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));
pub fn next_sibling(&self) -> Option<NodeId>
[src]
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);
pub fn is_removed(&self) -> bool
[src]
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
impl<T: Clone> Clone for Node<T>
[src]
impl<T: Debug> Debug for Node<T>
[src]
impl<T> Display for Node<T>
[src]
impl<T: Eq> Eq for Node<T>
[src]
impl<T: PartialEq> PartialEq<Node<T>> for Node<T>
[src]
impl<T> StructuralEq for Node<T>
[src]
impl<T> StructuralPartialEq for Node<T>
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for Node<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for Node<T> where
T: Send,
T: Send,
impl<T> Sync for Node<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Node<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Node<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,