Skip to content

Replace late initialization with let statement with an initializer #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 16 additions & 20 deletions src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,11 @@ impl eframe::App for MyApp {
|ui, row_range| {
for row in row_range {
let packet = self.data.raw_traffic[row].clone();
let color;
if self.dark_mode {
color = egui::Color32::WHITE;
let color = if self.dark_mode {
egui::Color32::WHITE
} else {
color = egui::Color32::BLACK;
}
egui::Color32::BLACK
};
ui.horizontal_wrapped(|ui| {
let text;
if self.show_sent_cmds {
Expand Down Expand Up @@ -365,12 +364,11 @@ impl eframe::App for MyApp {
}
});

let connect_text: &str;
if self.ready {
connect_text = "Disconnect";
let connect_text = if self.ready {
"Disconnect"
} else {
connect_text = "Connect";
}
"Connect"
};
if ui.button(connect_text).clicked() {
if let Ok(mut write_guard) = self.device_lock.write() {
if self.ready {
Expand Down Expand Up @@ -481,12 +479,11 @@ impl eframe::App for MyApp {
Print::MESSAGE(s) => {
let text = "[MSG] ".to_string();
ui.horizontal_wrapped(|ui| {
let color: egui::Color32;
if self.dark_mode {
color = egui::Color32::WHITE;
let color = if self.dark_mode {
egui::Color32::WHITE
} else {
color = egui::Color32::BLACK;
}
egui::Color32::BLACK
};
ui.label(RichText::new(text).color(color).font(
FontId::new(14.0, FontFamily::Monospace)));
let text = format!("{}", s);
Expand All @@ -506,12 +503,11 @@ impl eframe::App for MyApp {
}
Print::DEBUG(s) => {
if self.gui_conf.debug {
let color: egui::Color32;
if self.dark_mode {
color = egui::Color32::YELLOW;
let color = if self.dark_mode {
egui::Color32::YELLOW
} else {
color = egui::Color32::LIGHT_RED;
}
egui::Color32::LIGHT_RED
};
ui.horizontal_wrapped(|ui| {
let text = "[DBG] ".to_string();
ui.label(RichText::new(text).color(color).font(
Expand Down
9 changes: 4 additions & 5 deletions src/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,11 @@ pub fn serial_thread(gui_settings: GuiSettingsContainer,
if serial_read(&mut port, &mut serial_buf) {
if let Ok(mut write_guard) = raw_data_lock.write() {
// println!("received: {:?}", serial_buf);
let payloads: Vec<&str>;
if serial_buf.contains("\r\n") {
payloads = serial_buf.split("\r\n").collect::<Vec<&str>>();
let payloads: Vec<&str> = if serial_buf.contains("\r\n") {
serial_buf.split("\r\n").collect()
} else {
payloads = serial_buf.split("\0\0").collect::<Vec<&str>>();
}
serial_buf.split("\0\0").collect()
};
// println!("received split2: {:?}", payloads);
for payload in payloads.iter() {
let payload_string = payload.to_string();
Expand Down