Skip to content

Commit 40eccee

Browse files
committed
Use let-else in views::jobs::jobs_ui
1 parent c9a721a commit 40eccee

File tree

1 file changed

+37
-36
lines changed

1 file changed

+37
-36
lines changed

src/views/jobs.rs

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,46 +7,47 @@ pub fn jobs_ui(ui: &mut egui::Ui, view_state: &mut ViewState) {
77

88
let mut remove_job: Option<usize> = None;
99
for (idx, job) in view_state.jobs.iter_mut().enumerate() {
10-
if let Ok(status) = job.status.read() {
11-
ui.group(|ui| {
12-
ui.horizontal(|ui| {
13-
ui.label(&status.title);
14-
if ui.small_button("✖").clicked() {
15-
if job.handle.is_some() {
16-
job.should_remove = true;
17-
if let Err(e) = job.cancel.send(()) {
18-
eprintln!("Failed to cancel job: {e:?}");
19-
}
20-
} else {
21-
remove_job = Some(idx);
10+
let Ok(status) = job.status.read() else {
11+
continue;
12+
};
13+
ui.group(|ui| {
14+
ui.horizontal(|ui| {
15+
ui.label(&status.title);
16+
if ui.small_button("✖").clicked() {
17+
if job.handle.is_some() {
18+
job.should_remove = true;
19+
if let Err(e) = job.cancel.send(()) {
20+
eprintln!("Failed to cancel job: {e:?}");
2221
}
23-
}
24-
});
25-
let mut bar = ProgressBar::new(status.progress_percent);
26-
if let Some(items) = &status.progress_items {
27-
bar = bar.text(format!("{} / {}", items[0], items[1]));
28-
}
29-
bar.ui(ui);
30-
const STATUS_LENGTH: usize = 80;
31-
if let Some(err) = &status.error {
32-
let err_string = err.to_string();
33-
ui.colored_label(
34-
Color32::from_rgb(255, 0, 0),
35-
if err_string.len() > STATUS_LENGTH - 10 {
36-
format!("Error: {}...", &err_string[0..STATUS_LENGTH - 10])
37-
} else {
38-
format!("Error: {:width$}", err_string, width = STATUS_LENGTH - 7)
39-
},
40-
);
41-
} else {
42-
ui.label(if status.status.len() > STATUS_LENGTH - 3 {
43-
format!("{}...", &status.status[0..STATUS_LENGTH - 3])
4422
} else {
45-
format!("{:width$}", &status.status, width = STATUS_LENGTH)
46-
});
23+
remove_job = Some(idx);
24+
}
4725
}
4826
});
49-
}
27+
let mut bar = ProgressBar::new(status.progress_percent);
28+
if let Some(items) = &status.progress_items {
29+
bar = bar.text(format!("{} / {}", items[0], items[1]));
30+
}
31+
bar.ui(ui);
32+
const STATUS_LENGTH: usize = 80;
33+
if let Some(err) = &status.error {
34+
let err_string = err.to_string();
35+
ui.colored_label(
36+
Color32::from_rgb(255, 0, 0),
37+
if err_string.len() > STATUS_LENGTH - 10 {
38+
format!("Error: {}...", &err_string[0..STATUS_LENGTH - 10])
39+
} else {
40+
format!("Error: {:width$}", err_string, width = STATUS_LENGTH - 7)
41+
},
42+
);
43+
} else {
44+
ui.label(if status.status.len() > STATUS_LENGTH - 3 {
45+
format!("{}...", &status.status[0..STATUS_LENGTH - 3])
46+
} else {
47+
format!("{:width$}", &status.status, width = STATUS_LENGTH)
48+
});
49+
}
50+
});
5051
}
5152

5253
if let Some(idx) = remove_job {

0 commit comments

Comments
 (0)