Skip to main content

NodeMut

Struct NodeMut 

Source
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,

Source

pub fn id(&self) -> NodeId

Returns the ID of this node.

Source

pub fn tree(&mut self) -> &mut Tree<T>

Returns the tree owning this node.

Source

pub fn value(&mut self) -> &mut T

Returns the value of this node.

Source

pub fn parent(&mut self) -> Option<NodeMut<'_, T>>

Returns the parent of this node.

Source

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.

Source

pub fn prev_sibling(&mut self) -> Option<NodeMut<'_, T>>

Returns the previous sibling of this node.

Source

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.

Source

pub fn next_sibling(&mut self) -> Option<NodeMut<'_, T>>

Returns the next sibling of this node.

Source

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.

Source

pub fn first_child(&mut self) -> Option<NodeMut<'_, T>>

Returns the first child of this node.

Source

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.

Source

pub fn last_child(&mut self) -> Option<NodeMut<'_, T>>

Returns the last child of this node.

Source

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.

Source

pub fn has_siblings(&self) -> bool

Returns true if this node has siblings.

Source

pub fn has_children(&self) -> bool

Returns true if this node has children.

Source

pub fn append(&mut self, value: T) -> NodeMut<'_, T>

Appends a new child to this node.

Source

pub fn prepend(&mut self, value: T) -> NodeMut<'_, T>

Prepends a new child to this node.

Source

pub fn append_subtree(&mut self, subtree: Tree<T>) -> NodeMut<'_, T>

Appends a subtree, return the root of the merged subtree.

Source

pub fn prepend_subtree(&mut self, subtree: Tree<T>) -> NodeMut<'_, T>

Prepends a subtree, return the root of the merged subtree.

Source

pub fn insert_before(&mut self, value: T) -> NodeMut<'_, T>

Inserts a new sibling before this node.

§Panics

Panics if this node is an orphan.

Source

pub fn insert_after(&mut self, value: T) -> NodeMut<'_, T>

Inserts a new sibling after this node.

§Panics

Panics if this node is an orphan.

Source

pub fn detach(&mut self)

Detaches this node from its parent.

Source

pub fn append_id(&mut self, new_child_id: NodeId) -> NodeMut<'_, T>

Appends a child to this node.

§Panics

Panics if new_child_id is not valid.

Source

pub fn prepend_id(&mut self, new_child_id: NodeId) -> NodeMut<'_, T>

Prepends a child to this node.

§Panics

Panics if new_child_id is not valid.

Source

pub fn insert_id_before(&mut self, new_sibling_id: NodeId) -> NodeMut<'_, T>

Inserts a sibling before this node.

§Panics
  • Panics if new_sibling_id is not valid.
  • Panics if this node is an orphan.
Source

pub fn insert_id_after(&mut self, new_sibling_id: NodeId) -> NodeMut<'_, T>

Inserts a sibling after this node.

§Panics
  • Panics if new_sibling_id is not valid.
  • Panics if this node is an orphan.
Source

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.

Source

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,

Source

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<_>>(),
);
Source

pub fn sort_by<F>(&mut self, compare: F)
where F: FnMut(NodeRef<'_, T>, NodeRef<'_, T>) -> Ordering,

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<_>>(),
);
Source

pub fn sort_by_key<K, F>(&mut self, f: F)
where F: FnMut(NodeRef<'_, T>) -> K, K: Ord,

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§

Source§

impl<'a, T> Debug for NodeMut<'a, T>
where T: Debug + 'a,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'a, T> From<NodeMut<'a, T>> for NodeRef<'a, T>
where T: 'a,

Source§

fn from(node: NodeMut<'a, T>) -> NodeRef<'a, T>

Converts to this type from the input type.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> ConditionalSend for T
where T: Send,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

impl<T> Identity for T
where T: ?Sized,

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Settings for T
where T: 'static + Send + Sync,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more