History

Add 'inc()' convenience methods to progress

Sebastian Thiel committed 6 years ago

Commit 2e46c9b1 parent 4018c966 files · +53 −14Browse files

Showing the changes to git-features/src/progress (3 of 6 files). Show all

Unified · Split

3 files
  1. git-features/src/progress/log.rs +8 −0
  2. git-features/src/progress/mod.rs +27 −0
  3. git-features/src/progress/prodash.rs +4 −0
git-features/src/progress/log.rs+8−0
@@ -6,6 +6,7 @@ pub struct Log { · 5 unmodified lines
6 max: Option<u32>,6 max: Option<u32>,
7 unit: Option<&'static str>,7 unit: Option<&'static str>,
8 last_set: Option<std::time::SystemTime>,8 last_set: Option<std::time::SystemTime>,
9 step: u32,
9 current_level: usize,10 current_level: usize,
10 max_level: usize,11 max_level: usize,
11}12}
@@ -19,6 +20,7 @@ impl Log { · 7 unmodified lines
19 current_level: 0,20 current_level: 0,
20 max_level: max_level.unwrap_or(usize::MAX),21 max_level: max_level.unwrap_or(usize::MAX),
21 max: None,22 max: None,
23 step: 0,
22 unit: None,24 unit: None,
23 last_set: None,25 last_set: None,
24 }26 }
@@ -33,6 +35,7 @@ impl Progress for Log { · 8 unmodified lines
33 name: format!("{}::{}", self.name, Into::<String>::into(name)),35 name: format!("{}::{}", self.name, Into::<String>::into(name)),
34 current_level: self.current_level + 1,36 current_level: self.current_level + 1,
35 max_level: self.max_level,37 max_level: self.max_level,
38 step: 0,
36 max: None,39 max: None,
37 unit: None,40 unit: None,
38 last_set: None,41 last_set: None,
@@ -45,6 +48,7 @@ impl Progress for Log { · 6 unmodified lines
45 }48 }
46 49
47 fn set(&mut self, step: u32) {50 fn set(&mut self, step: u32) {
51 self.step = step;
48 if self.current_level > self.max_level {52 if self.current_level > self.max_level {
49 return;53 return;
50 }54 }
@@ -69,6 +73,10 @@ impl Progress for Log { · 18 unmodified lines
69 }73 }
70 }74 }
71 75
76 fn inc_by(&mut self, step: u32) {
77 self.set(self.step + step)
78 }
79
72 fn message(&mut self, level: MessageLevel, message: impl Into<String>) {80 fn message(&mut self, level: MessageLevel, message: impl Into<String>) {
73 let message: String = message.into();81 let message: String = message.into();
74 match level {82 match level {
git-features/src/progress/mod.rs+27−0
@@ -38,6 +38,20 @@ pub trait Progress { · 37 unmodified lines
38 /// **Note**: that this call has no effect unless `init(…)` was called before.38 /// **Note**: that this call has no effect unless `init(…)` was called before.
39 fn set(&mut self, step: u32);39 fn set(&mut self, step: u32);
40 40
41 /// Increment the current progress to the given `step`. The cost of this call is negligible,
42 /// making manual throttling *not* necessary.
43 ///
44 /// **Note**: that this call has no effect unless `init(…)` was called before.
45 fn inc_by(&mut self, step: u32);
46
47 /// Increment the current progress to the given 1. The cost of this call is negligible,
48 /// making manual throttling *not* necessary.
49 ///
50 /// **Note**: that this call has no effect unless `init(…)` was called before.
51 fn inc(&mut self) {
52 self.inc_by(1)
53 }
54
41 /// Create a `message` of the given `level` and store it with the progress tree.55 /// Create a `message` of the given `level` and store it with the progress tree.
42 ///56 ///
43 /// Use this to provide additional,human-readable information about the progress57 /// Use this to provide additional,human-readable information about the progress
@@ -71,6 +85,8 @@ impl Progress for Discard { · 27 unmodified lines
71 85
72 fn set(&mut self, _step: u32) {}86 fn set(&mut self, _step: u32) {}
73 87
88 fn inc_by(&mut self, _step: u32) {}
89
74 fn message(&mut self, _level: MessageLevel, _message: impl Into<String>) {}90 fn message(&mut self, _level: MessageLevel, _message: impl Into<String>) {}
75}91}
76 92
@@ -107,6 +123,13 @@ where · 30 unmodified lines
107 }123 }
108 }124 }
109 125
126 fn inc_by(&mut self, step: u32) {
127 match self {
128 Either::Left(l) => l.inc_by(step),
129 Either::Right(r) => r.inc_by(step),
130 }
131 }
132
110 fn message(&mut self, level: MessageLevel, message: impl Into<String>) {133 fn message(&mut self, level: MessageLevel, message: impl Into<String>) {
111 match self {134 match self {
112 Either::Left(l) => l.message(level, message),135 Either::Left(l) => l.message(level, message),
@@ -147,6 +170,10 @@ where · 34 unmodified lines
147 self.0.set(step)170 self.0.set(step)
148 }171 }
149 172
173 fn inc_by(&mut self, step: u32) {
174 self.0.inc_by(step)
175 }
176
150 fn message(&mut self, level: MessageLevel, message: impl Into<String>) {177 fn message(&mut self, level: MessageLevel, message: impl Into<String>) {
151 self.0.message(level, message)178 self.0.message(level, message)
152 }179 }
git-features/src/progress/prodash.rs+4−0
@@ -17,6 +17,10 @@ impl Progress for Item { · 16 unmodified lines
17 Item::set(self, step)17 Item::set(self, step)
18 }18 }
19 19
20 fn inc_by(&mut self, step: u32) {
21 self.inc_by(step)
22 }
23
20 fn message(&mut self, level: MessageLevel, message: impl Into<String>) {24 fn message(&mut self, level: MessageLevel, message: impl Into<String>) {
21 Item::message(25 Item::message(
22 self,26 self,