pub struct HistoryTree {
pub records: Vec<Record>,
pub cursor: Option<usize>,
}
Expand description
Stores information about history tree relations.
Fields§
§records: Vec<Record>
Stores records.
cursor: Option<usize>
History cursor.
Points to an index of records where all previous changes
are active, and those after are inactive.
When set to None
, it is assumed to point to the latest version.
Implementations§
Source§impl HistoryTree
impl HistoryTree
Sourcepub fn new() -> HistoryTree
pub fn new() -> HistoryTree
Creates a new history tree.
Examples found in repository?
More examples
examples/index.rs (line 10)
9fn main() {
10 let mut ht = HistoryTree::new();
11 let root = ht.root();
12 let _assets = ht.add(root);
13 let notes = ht.add(root);
14 let mut bar = ht.add(notes);
15 let _baz = ht.add(bar);
16 ht.print(root, 0);
17
18 ht.change(&mut bar);
19 ht.print(root, 0);
20
21 let src = ht.add(root);
22 let _file = ht.add(src);
23 let _foo = ht.add(src);
24 ht.print(root, 0);
25
26 ht.delete(bar);
27 ht.print(root, 0);
28
29 println!("--------- undo ----------");
30 for _ in 0..ht.records.len() - 1 {
31 ht.undo();
32 ht.print(root, 0);
33 }
34
35 println!("--------- redo ----------");
36 for _ in 0..ht.records.len() - 1 {
37 ht.redo();
38 ht.print(root, 0);
39 }
40}
Sourcepub fn root(&self) -> usize
pub fn root(&self) -> usize
Gets the root.
Examples found in repository?
More examples
examples/index.rs (line 11)
9fn main() {
10 let mut ht = HistoryTree::new();
11 let root = ht.root();
12 let _assets = ht.add(root);
13 let notes = ht.add(root);
14 let mut bar = ht.add(notes);
15 let _baz = ht.add(bar);
16 ht.print(root, 0);
17
18 ht.change(&mut bar);
19 ht.print(root, 0);
20
21 let src = ht.add(root);
22 let _file = ht.add(src);
23 let _foo = ht.add(src);
24 ht.print(root, 0);
25
26 ht.delete(bar);
27 ht.print(root, 0);
28
29 println!("--------- undo ----------");
30 for _ in 0..ht.records.len() - 1 {
31 ht.undo();
32 ht.print(root, 0);
33 }
34
35 println!("--------- redo ----------");
36 for _ in 0..ht.records.len() - 1 {
37 ht.redo();
38 ht.print(root, 0);
39 }
40}
Sourcepub fn cursor(&self) -> usize
pub fn cursor(&self) -> usize
Gets the cursor.
Examples found in repository?
examples/app.rs (line 52)
51 pub fn add(&mut self, text: String, parent: usize) -> usize {
52 let cursor = self.ht.cursor();
53 self.text.truncate(cursor + 1);
54
55 self.text.push(text);
56 self.ht.add(parent)
57 }
58
59 /// Changes a node.
60 pub fn change(&mut self, text: String, node: &mut usize) {
61 let cursor = self.ht.cursor();
62 self.text.truncate(cursor + 1);
63
64 self.text.push(text);
65 self.ht.change(node);
66 }
67
68 /// Deletes a node.
69 pub fn delete(&mut self, node: usize) {
70 let cursor = self.ht.cursor();
71 self.text.truncate(cursor + 1);
72
73 self.ht.delete(node);
74 }
Sourcepub fn add(&mut self, parent: usize) -> usize
pub fn add(&mut self, parent: usize) -> usize
Add new node.
Examples found in repository?
More examples
examples/index.rs (line 12)
9fn main() {
10 let mut ht = HistoryTree::new();
11 let root = ht.root();
12 let _assets = ht.add(root);
13 let notes = ht.add(root);
14 let mut bar = ht.add(notes);
15 let _baz = ht.add(bar);
16 ht.print(root, 0);
17
18 ht.change(&mut bar);
19 ht.print(root, 0);
20
21 let src = ht.add(root);
22 let _file = ht.add(src);
23 let _foo = ht.add(src);
24 ht.print(root, 0);
25
26 ht.delete(bar);
27 ht.print(root, 0);
28
29 println!("--------- undo ----------");
30 for _ in 0..ht.records.len() - 1 {
31 ht.undo();
32 ht.print(root, 0);
33 }
34
35 println!("--------- redo ----------");
36 for _ in 0..ht.records.len() - 1 {
37 ht.redo();
38 ht.print(root, 0);
39 }
40}
Sourcepub fn change(&mut self, node: &mut usize)
pub fn change(&mut self, node: &mut usize)
Change node.
Examples found in repository?
More examples
examples/index.rs (line 18)
9fn main() {
10 let mut ht = HistoryTree::new();
11 let root = ht.root();
12 let _assets = ht.add(root);
13 let notes = ht.add(root);
14 let mut bar = ht.add(notes);
15 let _baz = ht.add(bar);
16 ht.print(root, 0);
17
18 ht.change(&mut bar);
19 ht.print(root, 0);
20
21 let src = ht.add(root);
22 let _file = ht.add(src);
23 let _foo = ht.add(src);
24 ht.print(root, 0);
25
26 ht.delete(bar);
27 ht.print(root, 0);
28
29 println!("--------- undo ----------");
30 for _ in 0..ht.records.len() - 1 {
31 ht.undo();
32 ht.print(root, 0);
33 }
34
35 println!("--------- redo ----------");
36 for _ in 0..ht.records.len() - 1 {
37 ht.redo();
38 ht.print(root, 0);
39 }
40}
Sourcepub fn delete(&mut self, node: usize)
pub fn delete(&mut self, node: usize)
Delete node.
Examples found in repository?
More examples
examples/index.rs (line 26)
9fn main() {
10 let mut ht = HistoryTree::new();
11 let root = ht.root();
12 let _assets = ht.add(root);
13 let notes = ht.add(root);
14 let mut bar = ht.add(notes);
15 let _baz = ht.add(bar);
16 ht.print(root, 0);
17
18 ht.change(&mut bar);
19 ht.print(root, 0);
20
21 let src = ht.add(root);
22 let _file = ht.add(src);
23 let _foo = ht.add(src);
24 ht.print(root, 0);
25
26 ht.delete(bar);
27 ht.print(root, 0);
28
29 println!("--------- undo ----------");
30 for _ in 0..ht.records.len() - 1 {
31 ht.undo();
32 ht.print(root, 0);
33 }
34
35 println!("--------- redo ----------");
36 for _ in 0..ht.records.len() - 1 {
37 ht.redo();
38 ht.print(root, 0);
39 }
40}
Sourcepub fn children(&self, parent: usize) -> Vec<usize>
pub fn children(&self, parent: usize) -> Vec<usize>
Gets the names of children.
Examples found in repository?
examples/app.rs (line 83)
77 pub fn print(&self, parent: usize, tabs: u32) {
78 if tabs > 0 {
79 for _ in 0..tabs - 1 {print!(" ")}
80 print!("|-");
81 }
82 println!("{}", self.text[parent]);
83 for &ch in &self.ht.children(parent) {
84 self.print(ch, tabs + 1);
85 }
86 }
87
88 /// Goes one step back in history.
89 pub fn undo(&mut self) {self.ht.undo()}
90
91 /// Goes one step forward in history.
92 pub fn redo(&mut self) {self.ht.redo()}
93
94 /// Gets children.
95 pub fn children(&self, parent: usize) -> Vec<usize> {
96 self.ht.children(parent)
97 }
Sourcepub fn undo(&mut self)
pub fn undo(&mut self)
Goes back one step in history.
Examples found in repository?
More examples
examples/index.rs (line 31)
9fn main() {
10 let mut ht = HistoryTree::new();
11 let root = ht.root();
12 let _assets = ht.add(root);
13 let notes = ht.add(root);
14 let mut bar = ht.add(notes);
15 let _baz = ht.add(bar);
16 ht.print(root, 0);
17
18 ht.change(&mut bar);
19 ht.print(root, 0);
20
21 let src = ht.add(root);
22 let _file = ht.add(src);
23 let _foo = ht.add(src);
24 ht.print(root, 0);
25
26 ht.delete(bar);
27 ht.print(root, 0);
28
29 println!("--------- undo ----------");
30 for _ in 0..ht.records.len() - 1 {
31 ht.undo();
32 ht.print(root, 0);
33 }
34
35 println!("--------- redo ----------");
36 for _ in 0..ht.records.len() - 1 {
37 ht.redo();
38 ht.print(root, 0);
39 }
40}
Sourcepub fn redo(&mut self)
pub fn redo(&mut self)
Goes forward one step in history.
Examples found in repository?
More examples
examples/index.rs (line 37)
9fn main() {
10 let mut ht = HistoryTree::new();
11 let root = ht.root();
12 let _assets = ht.add(root);
13 let notes = ht.add(root);
14 let mut bar = ht.add(notes);
15 let _baz = ht.add(bar);
16 ht.print(root, 0);
17
18 ht.change(&mut bar);
19 ht.print(root, 0);
20
21 let src = ht.add(root);
22 let _file = ht.add(src);
23 let _foo = ht.add(src);
24 ht.print(root, 0);
25
26 ht.delete(bar);
27 ht.print(root, 0);
28
29 println!("--------- undo ----------");
30 for _ in 0..ht.records.len() - 1 {
31 ht.undo();
32 ht.print(root, 0);
33 }
34
35 println!("--------- redo ----------");
36 for _ in 0..ht.records.len() - 1 {
37 ht.redo();
38 ht.print(root, 0);
39 }
40}
Sourcepub fn print(&self, parent: usize, tabs: u32)
pub fn print(&self, parent: usize, tabs: u32)
Prints relations to standard output. This is used for debugging.
Examples found in repository?
examples/index.rs (line 16)
9fn main() {
10 let mut ht = HistoryTree::new();
11 let root = ht.root();
12 let _assets = ht.add(root);
13 let notes = ht.add(root);
14 let mut bar = ht.add(notes);
15 let _baz = ht.add(bar);
16 ht.print(root, 0);
17
18 ht.change(&mut bar);
19 ht.print(root, 0);
20
21 let src = ht.add(root);
22 let _file = ht.add(src);
23 let _foo = ht.add(src);
24 ht.print(root, 0);
25
26 ht.delete(bar);
27 ht.print(root, 0);
28
29 println!("--------- undo ----------");
30 for _ in 0..ht.records.len() - 1 {
31 ht.undo();
32 ht.print(root, 0);
33 }
34
35 println!("--------- redo ----------");
36 for _ in 0..ht.records.len() - 1 {
37 ht.redo();
38 ht.print(root, 0);
39 }
40}
Trait Implementations§
Source§impl Clone for HistoryTree
impl Clone for HistoryTree
Source§fn clone(&self) -> HistoryTree
fn clone(&self) -> HistoryTree
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for HistoryTree
impl Debug for HistoryTree
Source§impl PartialEq for HistoryTree
impl PartialEq for HistoryTree
impl Eq for HistoryTree
impl StructuralPartialEq for HistoryTree
Auto Trait Implementations§
impl Freeze for HistoryTree
impl RefUnwindSafe for HistoryTree
impl Send for HistoryTree
impl Sync for HistoryTree
impl Unpin for HistoryTree
impl UnwindSafe for HistoryTree
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