Skip to content

Commit 646878c

Browse files
committed
encapsulate set_percent_complete() into write_json() since it's only needed there
1 parent c99d806 commit 646878c

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

dsc_lib/src/progress.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,6 @@ impl ProgressBar {
115115
}
116116

117117
self.item_position += delta;
118-
119-
self.set_percent_complete();
120-
121118
if self.format == ProgressFormat::Json {
122119
self.write_json();
123120
} else {
@@ -168,7 +165,6 @@ impl ProgressBar {
168165
match self.format {
169166
ProgressFormat::Json => {
170167
self.item_count = len;
171-
self.set_percent_complete();
172168
},
173169
ProgressFormat::Default => {
174170
self.console_bar.pb_set_length(len);
@@ -177,21 +173,19 @@ impl ProgressBar {
177173
}
178174
}
179175

180-
fn write_json(&self) {
181-
if let Ok(json) = serde_json::to_string(&self.progress_value) {
182-
eprintln!("{json}");
183-
} else {
184-
trace!("{}", t!("progress.failedToSerialize", json = self.progress_value : {:?}));
185-
}
186-
}
187-
188-
fn set_percent_complete(&mut self) {
176+
fn write_json(&mut self) {
189177
if self.item_count > 0 {
190178
self.progress_value.percent_complete = if self.item_position >= self.item_count {
191179
100
192180
} else {
193181
u8::try_from((self.item_position * 100) / self.item_count).unwrap_or(100)
194182
};
195183
}
184+
185+
if let Ok(json) = serde_json::to_string(&self.progress_value) {
186+
eprintln!("{json}");
187+
} else {
188+
trace!("{}", t!("progress.failedToSerialize", json = self.progress_value : {:?}));
189+
}
196190
}
197191
}

0 commit comments

Comments
 (0)