Skip to content

Commit

Permalink
general minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
GyulyVGC committed Jan 10, 2024
1 parent 3dc9b73 commit 6352fc3
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 47 deletions.
6 changes: 3 additions & 3 deletions src/configs/types/config_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl Default for ConfigDevice {
Self {
device_name: Device::lookup()
.unwrap_or(None)
.unwrap_or(Device {
.unwrap_or_else(|| Device {
name: String::new(),
desc: None,
addresses: vec![],
Expand Down Expand Up @@ -62,7 +62,7 @@ impl ConfigDevice {
};
}
}
let standard_device = Device::lookup().unwrap_or(None).unwrap_or(Device {
let standard_device = Device::lookup().unwrap_or(None).unwrap_or_else(|| Device {
name: String::new(),
desc: None,
addresses: vec![],
Expand All @@ -88,7 +88,7 @@ mod tests {

pub fn load() -> Self {
confy::load_path::<ConfigDevice>(ConfigDevice::test_path())
.unwrap_or(ConfigDevice::default())
.unwrap_or_else(|_| ConfigDevice::default())
}

pub fn store(self) {
Expand Down
2 changes: 1 addition & 1 deletion src/configs/types/config_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ mod tests {

pub fn load() -> Self {
confy::load_path::<ConfigSettings>(ConfigSettings::test_path())
.unwrap_or(ConfigSettings::default())
.unwrap_or_else(|_| ConfigSettings::default())
}

pub fn store(self) {
Expand Down
2 changes: 1 addition & 1 deletion src/configs/types/config_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ mod tests {

pub fn load() -> Self {
confy::load_path::<ConfigWindow>(ConfigWindow::test_path())
.unwrap_or(ConfigWindow::default())
.unwrap_or_else(|_| ConfigWindow::default())
}

pub fn store(self) {
Expand Down
13 changes: 0 additions & 13 deletions src/gui/pages/settings_general_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,19 +257,6 @@ fn mmdb_selection_row(
}
};

// let mut input = TextInput::new("-", custom_path)
// .padding([0, 5])
// .font(font)
// .width(Length::Fixed(200.0))
// .style(if is_error {
// TextInputType::Error
// } else {
// TextInputType::Standard
// });
// if is_editable {
// input = input.on_input(message);
// }

Row::new()
.align_items(Alignment::Center)
.push(Text::new(format!("{caption}: ")).font(font))
Expand Down
12 changes: 0 additions & 12 deletions src/gui/pages/settings_style_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,18 +312,6 @@ fn lazy_custom_style_input(
custom_palette.is_err()
};

// let input = TextInput::new("-", custom_path)
// .on_input(Message::LoadStyle)
// .on_submit(Message::LoadStyle(custom_path.to_string()))
// .padding([0, 5])
// .font(font)
// .width(Length::Fixed(300.0))
// .style(if is_error {
// TextInputType::Error
// } else {
// TextInputType::Standard
// });

let button_row = Row::new()
.align_items(Alignment::Center)
.push(
Expand Down
4 changes: 2 additions & 2 deletions src/gui/types/sniffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,11 +583,11 @@ impl Sniffer {
};
let picked_file = rfd::AsyncFileDialog::new()
.set_title(file_info.action_info(language))
.add_filter("File type", &[file_info.get_extension()])
.add_filter(file_info.get_extension(), &[file_info.get_extension()])
.set_directory(starting_directory)
.pick_file()
.await
.unwrap_or(FileHandle::from(PathBuf::from(&old_file)));
.unwrap_or_else(|| FileHandle::from(PathBuf::from(&old_file)));

picked_file.path().to_string_lossy().to_string()
}
Expand Down
16 changes: 9 additions & 7 deletions src/networking/manage_packets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ pub fn modify_or_insert_in_map(
.or_insert(1);
}
})
.or_insert(InfoAddressPortPair {
.or_insert_with(|| InfoAddressPortPair {
mac_address1: mac_addresses.0,
mac_address2: mac_addresses.1,
transmitted_bytes: exchanged_bytes,
Expand Down Expand Up @@ -302,7 +302,7 @@ pub fn reverse_dns_lookup(
.and_modify(|data_info_host| {
data_info_host.data_info += other_data;
})
.or_insert(DataInfoHost {
.or_insert_with(|| DataInfoHost {
data_info: other_data,
is_favorite: false,
is_loopback,
Expand Down Expand Up @@ -418,7 +418,7 @@ fn is_broadcast_address(address: &str, my_interface_addresses: &[Address]) -> bo
.map(|address| {
address
.broadcast_addr
.unwrap_or("255.255.255.255".parse().unwrap())
.unwrap_or_else(|| "255.255.255.255".parse().unwrap())
.to_string()
})
.collect();
Expand Down Expand Up @@ -448,8 +448,9 @@ pub fn is_local_connection(address_to_lookup: &str, my_interface_addresses: &Vec
match address.addr {
IpAddr::V4(local_addr) if address_to_lookup_type.eq(&IPv4) => {
// check if the two IPv4 addresses are in the same subnet
let address_to_lookup_parsed: Ipv4Addr =
address_to_lookup.parse().unwrap_or(Ipv4Addr::from(0));
let address_to_lookup_parsed: Ipv4Addr = address_to_lookup
.parse()
.unwrap_or_else(|_| Ipv4Addr::from(0));
// remote is link local?
if address_to_lookup_parsed.is_link_local() {
ret_val = true;
Expand All @@ -472,8 +473,9 @@ pub fn is_local_connection(address_to_lookup: &str, my_interface_addresses: &Vec
}
IpAddr::V6(local_addr) if address_to_lookup_type.eq(&IPv6) => {
// check if the two IPv6 addresses are in the same subnet
let address_to_lookup_parsed: Ipv6Addr =
address_to_lookup.parse().unwrap_or(Ipv6Addr::from(0));
let address_to_lookup_parsed: Ipv6Addr = address_to_lookup
.parse()
.unwrap_or_else(|_| Ipv6Addr::from(0));
// remote is link local?
if address_to_lookup.starts_with("fe80") {
ret_val = true;
Expand Down
2 changes: 1 addition & 1 deletion src/networking/types/my_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl MyDevice {
return device;
}
}
Device::lookup().unwrap_or(None).unwrap_or(Device {
Device::lookup().unwrap_or(None).unwrap_or_else(|| Device {
name: String::new(),
desc: None,
addresses: vec![],
Expand Down
4 changes: 2 additions & 2 deletions src/networking/types/my_link_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl MyLinkType {
format!(
"{}: {} ({})",
link_type_translation(language),
l.get_name().unwrap_or(l.0.to_string()),
l.get_name().unwrap_or_else(|_| l.0.to_string()),
l.get_description().unwrap_or(String::new())
)
}
Expand All @@ -72,7 +72,7 @@ impl MyLinkType {
| Self::Unsupported(l) => {
let link_info = format!(
"{} ({})",
l.get_name().unwrap_or(l.0.to_string()),
l.get_name().unwrap_or_else(|_| l.0.to_string()),
l.get_description().unwrap_or(String::new())
);
TextType::highlighted_subtitle_with_desc(
Expand Down
2 changes: 1 addition & 1 deletion src/secondary_threads/check_updates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn is_newer_release_available(max_retries: u8, seconds_between_retries: u8) -> O
}

let mut latest_version = result_json
.unwrap_or(AppVersion {
.unwrap_or_else(|_| AppVersion {
name: String::from(":-("),
})
.name;
Expand Down
10 changes: 6 additions & 4 deletions src/secondary_threads/parse_packets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,12 @@ pub fn parse_packets(
.and_modify(|data_info| {
data_info.add_packet(exchanged_bytes, new_info.traffic_direction);
})
.or_insert(DataInfo::new_with_first_packet(
exchanged_bytes,
new_info.traffic_direction,
));
.or_insert_with(|| {
DataInfo::new_with_first_packet(
exchanged_bytes,
new_info.traffic_direction,
)
});
}
}
}
Expand Down

0 comments on commit 6352fc3

Please sign in to comment.