CursorMut

Struct CursorMut 

Source
pub struct CursorMut<'a, T> { /* private fields */ }
Expand description

A mutable Cursor can freely visit node in tree

Implementations§

Source§

impl<'a, T> CursorMut<'a, T>

Source

pub fn move_child(&mut self, at: usize)

Move this cursor to the specified child

§Panics

Panics if ‘at’ >= children_count()

Examples found in repository?
examples/basic.rs (line 17)
5fn main(){
6    let mut tree =
7        tr!(1)
8            / (tr!(2)
9                / tr!(5)
10                / tr!(6))
11            / (tr!(3)
12                / tr!(7)
13                / tr!(8))
14            / tr!(4);
15
16    let mut cursor = tree.cursor_mut();
17    cursor.move_child(0);
18    *cursor.current() = 10;
19    cursor.move_parent();
20    cursor.move_child(1);
21    let sub_tree = cursor.remove().unwrap();
22    for (depth,node) in sub_tree.df_iter().depth(){
23        for _ in 0..depth {
24            print!("-");
25        }
26        println!("{}",node);
27    }
28
29    let mut cursor = tree.cursor();
30    println!("children of root:");
31    for child in cursor.children() {
32        print!("{} ",child)
33    }
34    println!();
35    println!("root:{}",cursor.current());
36    cursor.move_child(0);
37    println!("first child:{}",cursor.current());
38    cursor.move_parent();
39    cursor.move_child(1);
40    println!("second child:{}",cursor.current());
41
42    for itr in tree.df_iter_mut() {
43        *itr += 1;
44        print!("{} ",itr);
45    }
46    println!();
47
48    for (depth,node) in tree.df_iter().depth(){
49        for _ in 0..depth {
50            print!("-");
51        }
52        println!("{}",node);
53    }
54
55    for itr in tree.bf_iter(){
56        print!("{} ",itr);
57    }
58}
Source

pub fn move_parent(&mut self)

move this cursor to its parent. Do nothing if it is already in the root node.

Examples found in repository?
examples/basic.rs (line 19)
5fn main(){
6    let mut tree =
7        tr!(1)
8            / (tr!(2)
9                / tr!(5)
10                / tr!(6))
11            / (tr!(3)
12                / tr!(7)
13                / tr!(8))
14            / tr!(4);
15
16    let mut cursor = tree.cursor_mut();
17    cursor.move_child(0);
18    *cursor.current() = 10;
19    cursor.move_parent();
20    cursor.move_child(1);
21    let sub_tree = cursor.remove().unwrap();
22    for (depth,node) in sub_tree.df_iter().depth(){
23        for _ in 0..depth {
24            print!("-");
25        }
26        println!("{}",node);
27    }
28
29    let mut cursor = tree.cursor();
30    println!("children of root:");
31    for child in cursor.children() {
32        print!("{} ",child)
33    }
34    println!();
35    println!("root:{}",cursor.current());
36    cursor.move_child(0);
37    println!("first child:{}",cursor.current());
38    cursor.move_parent();
39    cursor.move_child(1);
40    println!("second child:{}",cursor.current());
41
42    for itr in tree.df_iter_mut() {
43        *itr += 1;
44        print!("{} ",itr);
45    }
46    println!();
47
48    for (depth,node) in tree.df_iter().depth(){
49        for _ in 0..depth {
50            print!("-");
51        }
52        println!("{}",node);
53    }
54
55    for itr in tree.bf_iter(){
56        print!("{} ",itr);
57    }
58}
Source

pub fn move_root(&mut self)

Move this cursor to its root. Do nothing if it is already in the root node.

Source

pub fn current(&self) -> &'a mut T

Return the reference to the current

Examples found in repository?
examples/basic.rs (line 18)
5fn main(){
6    let mut tree =
7        tr!(1)
8            / (tr!(2)
9                / tr!(5)
10                / tr!(6))
11            / (tr!(3)
12                / tr!(7)
13                / tr!(8))
14            / tr!(4);
15
16    let mut cursor = tree.cursor_mut();
17    cursor.move_child(0);
18    *cursor.current() = 10;
19    cursor.move_parent();
20    cursor.move_child(1);
21    let sub_tree = cursor.remove().unwrap();
22    for (depth,node) in sub_tree.df_iter().depth(){
23        for _ in 0..depth {
24            print!("-");
25        }
26        println!("{}",node);
27    }
28
29    let mut cursor = tree.cursor();
30    println!("children of root:");
31    for child in cursor.children() {
32        print!("{} ",child)
33    }
34    println!();
35    println!("root:{}",cursor.current());
36    cursor.move_child(0);
37    println!("first child:{}",cursor.current());
38    cursor.move_parent();
39    cursor.move_child(1);
40    println!("second child:{}",cursor.current());
41
42    for itr in tree.df_iter_mut() {
43        *itr += 1;
44        print!("{} ",itr);
45    }
46    println!();
47
48    for (depth,node) in tree.df_iter().depth(){
49        for _ in 0..depth {
50            print!("-");
51        }
52        println!("{}",node);
53    }
54
55    for itr in tree.bf_iter(){
56        print!("{} ",itr);
57    }
58}
Source

pub fn children_count(&self) -> usize

Get the count of children in current node

Source

pub fn children(&self) -> ChildrenIterMut<'a, T>

Get a immutable children iterator

Source

pub fn is_root(&self) -> bool

Return true if current node is the root

Source

pub fn is_leaf(&self) -> bool

Return true if current node is a leaf

Source

pub fn remove(self) -> Option<Tree<T>>

Remove a sub-tree and consume the cursor
return None when current node is root

Examples found in repository?
examples/basic.rs (line 21)
5fn main(){
6    let mut tree =
7        tr!(1)
8            / (tr!(2)
9                / tr!(5)
10                / tr!(6))
11            / (tr!(3)
12                / tr!(7)
13                / tr!(8))
14            / tr!(4);
15
16    let mut cursor = tree.cursor_mut();
17    cursor.move_child(0);
18    *cursor.current() = 10;
19    cursor.move_parent();
20    cursor.move_child(1);
21    let sub_tree = cursor.remove().unwrap();
22    for (depth,node) in sub_tree.df_iter().depth(){
23        for _ in 0..depth {
24            print!("-");
25        }
26        println!("{}",node);
27    }
28
29    let mut cursor = tree.cursor();
30    println!("children of root:");
31    for child in cursor.children() {
32        print!("{} ",child)
33    }
34    println!();
35    println!("root:{}",cursor.current());
36    cursor.move_child(0);
37    println!("first child:{}",cursor.current());
38    cursor.move_parent();
39    cursor.move_child(1);
40    println!("second child:{}",cursor.current());
41
42    for itr in tree.df_iter_mut() {
43        *itr += 1;
44        print!("{} ",itr);
45    }
46    println!();
47
48    for (depth,node) in tree.df_iter().depth(){
49        for _ in 0..depth {
50            print!("-");
51        }
52        println!("{}",node);
53    }
54
55    for itr in tree.bf_iter(){
56        print!("{} ",itr);
57    }
58}
Source

pub fn add_child(&mut self, tree: Tree<T>)

Add a sub-tree to children of current node

Auto Trait Implementations§

§

impl<'a, T> Freeze for CursorMut<'a, T>

§

impl<'a, T> RefUnwindSafe for CursorMut<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> !Send for CursorMut<'a, T>

§

impl<'a, T> !Sync for CursorMut<'a, T>

§

impl<'a, T> Unpin for CursorMut<'a, T>

§

impl<'a, T> UnwindSafe for CursorMut<'a, T>
where T: RefUnwindSafe,

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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