Skip to content

Commit 5e45624

Browse files
authored
Merge pull request #6 from lonesometraveler/clippy_4
Replace late initialization with let statement with an initializer
2 parents 56dcc13 + 75f5a58 commit 5e45624

File tree

2 files changed

+20
-25
lines changed

2 files changed

+20
-25
lines changed

src/gui.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,11 @@ impl eframe::App for MyApp {
219219
|ui, row_range| {
220220
for row in row_range {
221221
let packet = self.data.raw_traffic[row].clone();
222-
let color;
223-
if self.dark_mode {
224-
color = egui::Color32::WHITE;
222+
let color = if self.dark_mode {
223+
egui::Color32::WHITE
225224
} else {
226-
color = egui::Color32::BLACK;
227-
}
225+
egui::Color32::BLACK
226+
};
228227
ui.horizontal_wrapped(|ui| {
229228
let text;
230229
if self.show_sent_cmds {
@@ -365,12 +364,11 @@ impl eframe::App for MyApp {
365364
}
366365
});
367366

368-
let connect_text: &str;
369-
if self.ready {
370-
connect_text = "Disconnect";
367+
let connect_text = if self.ready {
368+
"Disconnect"
371369
} else {
372-
connect_text = "Connect";
373-
}
370+
"Connect"
371+
};
374372
if ui.button(connect_text).clicked() {
375373
if let Ok(mut write_guard) = self.device_lock.write() {
376374
if self.ready {
@@ -481,12 +479,11 @@ impl eframe::App for MyApp {
481479
Print::MESSAGE(s) => {
482480
let text = "[MSG] ".to_string();
483481
ui.horizontal_wrapped(|ui| {
484-
let color: egui::Color32;
485-
if self.dark_mode {
486-
color = egui::Color32::WHITE;
482+
let color = if self.dark_mode {
483+
egui::Color32::WHITE
487484
} else {
488-
color = egui::Color32::BLACK;
489-
}
485+
egui::Color32::BLACK
486+
};
490487
ui.label(RichText::new(text).color(color).font(
491488
FontId::new(14.0, FontFamily::Monospace)));
492489
let text = format!("{}", s);
@@ -506,12 +503,11 @@ impl eframe::App for MyApp {
506503
}
507504
Print::DEBUG(s) => {
508505
if self.gui_conf.debug {
509-
let color: egui::Color32;
510-
if self.dark_mode {
511-
color = egui::Color32::YELLOW;
506+
let color = if self.dark_mode {
507+
egui::Color32::YELLOW
512508
} else {
513-
color = egui::Color32::LIGHT_RED;
514-
}
509+
egui::Color32::LIGHT_RED
510+
};
515511
ui.horizontal_wrapped(|ui| {
516512
let text = "[DBG] ".to_string();
517513
ui.label(RichText::new(text).color(color).font(

src/serial.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,11 @@ pub fn serial_thread(gui_settings: GuiSettingsContainer,
185185
if serial_read(&mut port, &mut serial_buf) {
186186
if let Ok(mut write_guard) = raw_data_lock.write() {
187187
// println!("received: {:?}", serial_buf);
188-
let payloads: Vec<&str>;
189-
if serial_buf.contains("\r\n") {
190-
payloads = serial_buf.split("\r\n").collect::<Vec<&str>>();
188+
let payloads: Vec<&str> = if serial_buf.contains("\r\n") {
189+
serial_buf.split("\r\n").collect()
191190
} else {
192-
payloads = serial_buf.split("\0\0").collect::<Vec<&str>>();
193-
}
191+
serial_buf.split("\0\0").collect()
192+
};
194193
// println!("received split2: {:?}", payloads);
195194
for payload in payloads.iter() {
196195
let payload_string = payload.to_string();

0 commit comments

Comments
 (0)