Enum id_tree::MoveBehavior [−][src]
Describes the possible behaviors of the Tree::move_node
method.
Variants
Sets the Node
in question as the new root Node
, leaving all children in their place (in
other words, they will travel with the Node
being moved).
If there is already a root Node
in place, it will be attached as the last child of the new
root.
use id_tree::*; use id_tree::InsertBehavior::*; use id_tree::MoveBehavior::*; let mut tree: Tree<i32> = Tree::new(); let root_id = tree.insert(Node::new(1), AsRoot).unwrap(); let child_id = tree.insert(Node::new(2), UnderNode(&root_id)).unwrap(); let grandchild_id = tree.insert(Node::new(3), UnderNode(&child_id)).unwrap(); tree.move_node(&grandchild_id, ToRoot).unwrap(); assert_eq!(tree.root_node_id(), Some(&grandchild_id)); assert!(tree.get(&grandchild_id).unwrap().children().contains(&root_id)); assert!(!tree.get(&child_id).unwrap().children().contains(&grandchild_id));
ToParent(&'a NodeId)
Moves a Node
inside the Tree
to a new parent leaving all children in their place.
If the new parent (let’s call it B
) is a descendant of the Node
being moved (A
), then
the direct child of A
on the path from A
to B
will be shifted upwards to take the
place of its parent (A
). All other children of A
will be left alone, meaning they will
travel with it down the Tree
.
Please note that during the “shift-up” part of the above scenario, the Node
being shifted
up will always be added as the last child of its new parent.
use id_tree::*; use id_tree::InsertBehavior::*; use id_tree::MoveBehavior::*; let mut tree: Tree<i32> = Tree::new(); let root_id = tree.insert(Node::new(1), AsRoot).ok().unwrap(); let first_child_id = tree.insert(Node::new(2), UnderNode(&root_id)).unwrap(); let second_child_id = tree.insert(Node::new(3), UnderNode(&root_id)).unwrap(); let grandchild_id = tree.insert(Node::new(4), UnderNode(&first_child_id)).unwrap(); tree.move_node(&grandchild_id, ToParent(&second_child_id)).unwrap(); assert!(!tree.get(&first_child_id).unwrap().children().contains(&grandchild_id)); assert!(tree.get(&second_child_id).unwrap().children().contains(&grandchild_id));
Auto Trait Implementations
impl<'a> RefUnwindSafe for MoveBehavior<'a>
impl<'a> Send for MoveBehavior<'a>
impl<'a> Sync for MoveBehavior<'a>
impl<'a> Unpin for MoveBehavior<'a>
impl<'a> UnwindSafe for MoveBehavior<'a>
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,
pub 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, 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.
pub 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>,