pub struct NodeMut<'a, T>where
T: 'a,{ /* private fields */ }Expand description
Node mutator.
Implementations§
Source§impl<'a, T> NodeMut<'a, T>where
T: 'a,
impl<'a, T> NodeMut<'a, T>where
T: 'a,
Sourcepub fn into_parent(self) -> Result<NodeMut<'a, T>, NodeMut<'a, T>>
pub fn into_parent(self) -> Result<NodeMut<'a, T>, NodeMut<'a, T>>
Returns the parent of this node.
Returns Ok(parent) if possible and Err(self) otherwise
so the caller can recover the current position.
Sourcepub fn prev_sibling(&mut self) -> Option<NodeMut<'_, T>>
pub fn prev_sibling(&mut self) -> Option<NodeMut<'_, T>>
Returns the previous sibling of this node.
Sourcepub fn into_prev_sibling(self) -> Result<NodeMut<'a, T>, NodeMut<'a, T>>
pub fn into_prev_sibling(self) -> Result<NodeMut<'a, T>, NodeMut<'a, T>>
Returns the previous sibling of this node.
Returns Ok(prev_sibling) if possible and Err(self) otherwise
so the caller can recover the current position.
Sourcepub fn next_sibling(&mut self) -> Option<NodeMut<'_, T>>
pub fn next_sibling(&mut self) -> Option<NodeMut<'_, T>>
Returns the next sibling of this node.
Sourcepub fn into_next_sibling(self) -> Result<NodeMut<'a, T>, NodeMut<'a, T>>
pub fn into_next_sibling(self) -> Result<NodeMut<'a, T>, NodeMut<'a, T>>
Returns the next sibling of this node.
Returns Ok(next_sibling) if possible and Err(self) otherwise
so the caller can recover the current position.
Sourcepub fn first_child(&mut self) -> Option<NodeMut<'_, T>>
pub fn first_child(&mut self) -> Option<NodeMut<'_, T>>
Returns the first child of this node.
Sourcepub fn into_first_child(self) -> Result<NodeMut<'a, T>, NodeMut<'a, T>>
pub fn into_first_child(self) -> Result<NodeMut<'a, T>, NodeMut<'a, T>>
Returns the first child of this node.
Returns Ok(first_child) if possible and Err(self) otherwise
so the caller can recover the current position.
Sourcepub fn last_child(&mut self) -> Option<NodeMut<'_, T>>
pub fn last_child(&mut self) -> Option<NodeMut<'_, T>>
Returns the last child of this node.
Sourcepub fn into_last_child(self) -> Result<NodeMut<'a, T>, NodeMut<'a, T>>
pub fn into_last_child(self) -> Result<NodeMut<'a, T>, NodeMut<'a, T>>
Returns the last child of this node.
Returns Ok(last_child) if possible and Err(self) otherwise
so the caller can recover the current position.
Sourcepub fn has_siblings(&self) -> bool
pub fn has_siblings(&self) -> bool
Returns true if this node has siblings.
Sourcepub fn has_children(&self) -> bool
pub fn has_children(&self) -> bool
Returns true if this node has children.
Sourcepub fn append_subtree(&mut self, subtree: Tree<T>) -> NodeMut<'_, T>
pub fn append_subtree(&mut self, subtree: Tree<T>) -> NodeMut<'_, T>
Appends a subtree, return the root of the merged subtree.
Sourcepub fn prepend_subtree(&mut self, subtree: Tree<T>) -> NodeMut<'_, T>
pub fn prepend_subtree(&mut self, subtree: Tree<T>) -> NodeMut<'_, T>
Prepends a subtree, return the root of the merged subtree.
Sourcepub fn insert_before(&mut self, value: T) -> NodeMut<'_, T>
pub fn insert_before(&mut self, value: T) -> NodeMut<'_, T>
Sourcepub fn insert_after(&mut self, value: T) -> NodeMut<'_, T>
pub fn insert_after(&mut self, value: T) -> NodeMut<'_, T>
Sourcepub fn prepend_id(&mut self, new_child_id: NodeId) -> NodeMut<'_, T>
pub fn prepend_id(&mut self, new_child_id: NodeId) -> NodeMut<'_, T>
Sourcepub fn insert_id_before(&mut self, new_sibling_id: NodeId) -> NodeMut<'_, T>
pub fn insert_id_before(&mut self, new_sibling_id: NodeId) -> NodeMut<'_, T>
Inserts a sibling before this node.
§Panics
- Panics if
new_sibling_idis not valid. - Panics if this node is an orphan.
Sourcepub fn insert_id_after(&mut self, new_sibling_id: NodeId) -> NodeMut<'_, T>
pub fn insert_id_after(&mut self, new_sibling_id: NodeId) -> NodeMut<'_, T>
Inserts a sibling after this node.
§Panics
- Panics if
new_sibling_idis not valid. - Panics if this node is an orphan.
Sourcepub fn reparent_from_id_append(&mut self, from_id: NodeId)
pub fn reparent_from_id_append(&mut self, from_id: NodeId)
Reparents the children of a node, appending them to this node.
§Panics
Panics if from_id is not valid.
Sourcepub fn reparent_from_id_prepend(&mut self, from_id: NodeId)
pub fn reparent_from_id_prepend(&mut self, from_id: NodeId)
Reparents the children of a node, prepending them to this node.
§Panics
Panics if from_id is not valid.
Source§impl<'a, T> NodeMut<'a, T>where
T: 'a,
impl<'a, T> NodeMut<'a, T>where
T: 'a,
Sourcepub fn sort(&mut self)where
T: Ord,
pub fn sort(&mut self)where
T: Ord,
Sort children by value in ascending order.
§Examples
use ego_tree::tree;
let mut tree = tree!('a' => { 'd', 'c', 'b' });
tree.root_mut().sort();
assert_eq!(
vec![&'b', &'c', &'d'],
tree.root()
.children()
.map(|n| n.value())
.collect::<Vec<_>>(),
);Sourcepub fn sort_by<F>(&mut self, compare: F)
pub fn sort_by<F>(&mut self, compare: F)
Sort children by NodeRef in ascending order using a comparison function.
§Examples
use ego_tree::tree;
let mut tree = tree!('a' => { 'c', 'd', 'b' });
tree.root_mut().sort_by(|a, b| b.value().cmp(a.value()));
assert_eq!(
vec![&'d', &'c', &'b'],
tree.root()
.children()
.map(|n| n.value())
.collect::<Vec<_>>(),
);
// Example for sort_by_id.
tree.root_mut().sort_by(|a, b| a.id().cmp(&b.id()));
assert_eq!(
vec![&'c', &'d', &'b'],
tree.root()
.children()
.map(|n| n.value())
.collect::<Vec<_>>(),
);Sourcepub fn sort_by_key<K, F>(&mut self, f: F)
pub fn sort_by_key<K, F>(&mut self, f: F)
Sort children by NodeRef’s key in ascending order using a key extraction function.
§Examples
use ego_tree::tree;
let mut tree = tree!("1a" => { "2b", "4c", "3d" });
tree.root_mut().sort_by_key(|a| a.value().split_at(1).0.parse::<i32>().unwrap());
assert_eq!(
vec!["2b", "3d", "4c"],
tree.root()
.children()
.map(|n| *n.value())
.collect::<Vec<_>>(),
);
// Example for sort_by_id.
tree.root_mut().sort_by_key(|n| n.id());
assert_eq!(
vec![&"2b", &"4c", &"3d"],
tree.root()
.children()
.map(|n| n.value())
.collect::<Vec<_>>(),
);Trait Implementations§
Auto Trait Implementations§
impl<'a, T> !UnwindSafe for NodeMut<'a, T>
impl<'a, T> Freeze for NodeMut<'a, T>
impl<'a, T> RefUnwindSafe for NodeMut<'a, T>where
T: RefUnwindSafe,
impl<'a, T> Send for NodeMut<'a, T>where
T: Send,
impl<'a, T> Sync for NodeMut<'a, T>where
T: Sync,
impl<'a, T> Unpin for NodeMut<'a, T>
impl<'a, T> UnsafeUnpin for NodeMut<'a, T>
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ConditionalSend for Twhere
T: Send,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more