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>
impl<'a, T> CursorMut<'a, T>
Sourcepub fn move_child(&mut self, at: usize)
pub fn move_child(&mut self, at: usize)
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}
Sourcepub fn move_parent(&mut self)
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}
Sourcepub fn move_root(&mut self)
pub fn move_root(&mut self)
Move this cursor to its root. Do nothing if it is already in the root node.
Sourcepub fn current(&self) -> &'a mut T
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}
Sourcepub fn children_count(&self) -> usize
pub fn children_count(&self) -> usize
Get the count of children in current node
Sourcepub fn children(&self) -> ChildrenIterMut<'a, T> ⓘ
pub fn children(&self) -> ChildrenIterMut<'a, T> ⓘ
Get a immutable children iterator
Sourcepub fn remove(self) -> Option<Tree<T>>
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}
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> 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
Mutably borrows from an owned value. Read more