Skip to content

Commit

Permalink
Make clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
nokyan committed Apr 5, 2024
1 parent 07dd202 commit abf17cc
Show file tree
Hide file tree
Showing 22 changed files with 178 additions and 199 deletions.
2 changes: 1 addition & 1 deletion src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl Application {
if PROFILE == "Devel" {
info!(
"You are running a development version of Resources, things may be slow or break!"
)
);
}

ApplicationExtManual::run(self);
Expand Down
2 changes: 1 addition & 1 deletion src/bin/resources-processes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ fn main() -> Result<()> {

handle.write_all(&encoded)?;

handle.flush()?
handle.flush()?;
}
}
9 changes: 4 additions & 5 deletions src/ui/pages/applications/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ impl ResApplications {
if let Some(sorter) = sorter.downcast_ref::<gtk::ColumnViewSorter>() {
let current_column = sorter.primary_sort_column().map(|column| column.as_ptr() as usize).unwrap_or_default();

let current_column_number = this.imp().columns.borrow().iter().enumerate().find(|(_, column)| column.as_ptr() as usize == current_column).map(|(i, _)| i as u32).unwrap_or(0); // 0 corresponds to the name column
let current_column_number = this.imp().columns.borrow().iter().enumerate().find(|(_, column)| column.as_ptr() as usize == current_column).map_or(0, |(i, _)| i as u32); // 0 corresponds to the name column

if SETTINGS.apps_sort_by() != current_column_number {
let _ = SETTINGS.set_apps_sort_by(current_column_number);
Expand Down Expand Up @@ -480,8 +480,7 @@ impl ResApplications {
|| item.name().to_lowercase().contains(&search_string)
|| item
.id()
.map(|id| id.to_lowercase().contains(&search_string))
.unwrap_or_default()
.is_some_and(|id| id.to_lowercase().contains(&search_string))
|| item
.description()
.unwrap_or_default()
Expand Down Expand Up @@ -558,7 +557,7 @@ impl ResApplications {
store.extend_from_slice(&items);

if let Some(sorter) = imp.column_view.borrow().sorter() {
sorter.changed(gtk::SorterChange::Different)
sorter.changed(gtk::SorterChange::Different);
}

// -1 because we don't want to count System Processes
Expand Down Expand Up @@ -893,7 +892,7 @@ impl ResApplications {

SETTINGS.connect_apps_show_drive_write_speed(
clone!(@strong write_speed_col => move |visible| {
write_speed_col.set_visible(visible)
write_speed_col.set_visible(visible);
}),
);

Expand Down
2 changes: 1 addition & 1 deletion src/ui/pages/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ impl ResCPU {
&convert_frequency(frequency as f64)
));
} else {
curr_threadbox.set_title_label(&i18n_f("CPU {}", &[&(i + 1).to_string()]))
curr_threadbox.set_title_label(&i18n_f("CPU {}", &[&(i + 1).to_string()]));
}
*old_thread_usage = new_thread_usage;
}
Expand Down
20 changes: 10 additions & 10 deletions src/ui/pages/gpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,7 @@ impl ResGPU {

imp.manufacturer.set_subtitle(
&gpu.get_vendor()
.map(|vendor| vendor.name().to_string())
.unwrap_or_else(|_| i18n("N/A")),
.map_or_else(|_| i18n("N/A"), |vendor| vendor.name().to_string()),
);

imp.pci_slot.set_subtitle(&gpu.pci_slot().to_string());
Expand Down Expand Up @@ -293,9 +292,10 @@ impl ResGPU {
nvidia: _,
} = gpu_data;

let mut usage_percentage_string = usage_fraction
.map(|fraction| format!("{} %", (fraction * 100.0).round()))
.unwrap_or(i18n("N/A"));
let mut usage_percentage_string = usage_fraction.map_or_else(
|| i18n("N/A"),
|fraction| format!("{} %", (fraction * 100.0).round()),
);

imp.gpu_usage.set_subtitle(&usage_percentage_string);
imp.gpu_usage
Expand Down Expand Up @@ -351,10 +351,10 @@ impl ResGPU {
None
};

let vram_percentage_string = used_vram_fraction
.as_ref()
.map(|fraction| format!("{} %", (fraction * 100.0).round()))
.unwrap_or(i18n("N/A"));
let vram_percentage_string = used_vram_fraction.as_ref().map_or_else(
|| i18n("N/A"),
|fraction| format!("{} %", (fraction * 100.0).round()),
);

let vram_subtitle = if let (Some(total_vram), Some(used_vram)) = (total_vram, used_vram) {
format!(
Expand Down Expand Up @@ -417,6 +417,6 @@ impl ResGPU {
usage_percentage_string.push_str(&temperature_string);
}

self.set_property("tab_usage_string", &usage_percentage_string)
self.set_property("tab_usage_string", &usage_percentage_string);
}
}
18 changes: 4 additions & 14 deletions src/ui/pages/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,27 +238,17 @@ impl ResMemory {

let form_factor = memory_devices.iter().find(|md| md.installed).map_or_else(
|| i18n("N/A"),
|md| {
md.form_factor
.as_ref()
.cloned()
.unwrap_or_else(|| i18n("N/A"))
},
|md| md.form_factor.clone().unwrap_or_else(|| i18n("N/A")),
);

let r#type = memory_devices.iter().find(|md| md.installed).map_or_else(
|| i18n("N/A"),
|md| md.r#type.as_ref().cloned().unwrap_or_else(|| i18n("N/A")),
|md| md.r#type.clone().unwrap_or_else(|| i18n("N/A")),
);

let type_detail = memory_devices.iter().find(|md| md.installed).map_or_else(
|| i18n("N/A"),
|md| {
md.type_detail
.as_ref()
.cloned()
.unwrap_or_else(|| i18n("N/A"))
},
|md| md.type_detail.clone().unwrap_or_else(|| i18n("N/A")),
);

let total_memory = memory_devices
Expand Down Expand Up @@ -306,7 +296,7 @@ impl ResMemory {
this.setup_properties(memory_devices);
imp.properties.set_visible(true);
}
imp.authentication_banner.set_revealed(false)
imp.authentication_banner.set_revealed(false);
}));
}

Expand Down
9 changes: 3 additions & 6 deletions src/ui/pages/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,16 +253,14 @@ impl ResNetwork {
imp.manufacturer.set_subtitle(
&network_interface
.vendor
.as_ref()
.cloned()
.clone()
.unwrap_or_else(|| i18n("N/A")),
);

imp.driver.set_subtitle(
&network_interface
.driver_name
.as_ref()
.cloned()
.clone()
.unwrap_or_else(|| i18n("N/A")),
);

Expand All @@ -275,8 +273,7 @@ impl ResNetwork {

let hw_address = network_interface
.hw_address
.as_ref()
.cloned()
.clone()
.unwrap_or_else(|| i18n("N/A"));

if hw_address.is_empty() {
Expand Down
10 changes: 5 additions & 5 deletions src/ui/pages/processes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ impl ResProcesses {
if let Some(sorter) = sorter.downcast_ref::<gtk::ColumnViewSorter>() {
let current_column = sorter.primary_sort_column().map(|column| column.as_ptr() as usize).unwrap_or_default();

let current_column_number = this.imp().columns.borrow().iter().enumerate().find(|(_, column)| column.as_ptr() as usize == current_column).map(|(i, _)| i as u32).unwrap_or(3); // 3 corresponds to the memory column
let current_column_number = this.imp().columns.borrow().iter().enumerate().find(|(_, column)| column.as_ptr() as usize == current_column).map_or(3, |(i, _)| i as u32); // 3 corresponds to the memory column

if SETTINGS.processes_sort_by() != current_column_number {
let _ = SETTINGS.set_processes_sort_by(current_column_number);
Expand Down Expand Up @@ -539,7 +539,7 @@ impl ResProcesses {
store.extend_from_slice(&items);

if let Some(sorter) = imp.column_view.borrow().sorter() {
sorter.changed(gtk::SorterChange::Different)
sorter.changed(gtk::SorterChange::Different);
}

self.set_property(
Expand Down Expand Up @@ -877,7 +877,7 @@ impl ResProcesses {

SETTINGS.connect_processes_show_drive_read_speed(
clone!(@strong read_speed_col => move |visible| {
read_speed_col.set_visible(visible)
read_speed_col.set_visible(visible);
}),
);

Expand Down Expand Up @@ -930,7 +930,7 @@ impl ResProcesses {

SETTINGS.connect_processes_show_drive_read_total(
clone!(@strong read_total_col => move |visible| {
read_total_col.set_visible(visible)
read_total_col.set_visible(visible);
}),
);

Expand Down Expand Up @@ -983,7 +983,7 @@ impl ResProcesses {

SETTINGS.connect_processes_show_drive_write_speed(
clone!(@strong write_speed_col => move |visible| {
write_speed_col.set_visible(visible)
write_speed_col.set_visible(visible);
}),
);

Expand Down
8 changes: 4 additions & 4 deletions src/ui/widgets/stack_sidebar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,7 @@ impl ResStackSidebar {
);

// TODO: generalize to "uses_meter"?
if !child.property::<bool>("uses_progress_bar") {
sidebar_item.set_progress_bar_visible(false);
sidebar_item.set_graph_visible(false);
} else {
if child.property::<bool>("uses_progress_bar") {
if child.has_property("main_graph_color", Some(glib::Bytes::static_type())) {
let b = child.property::<glib::Bytes>("main_graph_color");
sidebar_item.set_graph_color(b[0], b[1], b[2]);
Expand All @@ -186,6 +183,9 @@ impl ResStackSidebar {
.bind_property("usage", &sidebar_item, "usage")
.sync_create()
.build();
} else {
sidebar_item.set_progress_bar_visible(false);
sidebar_item.set_graph_visible(false);
}

let row = gtk::ListBoxRow::builder()
Expand Down
2 changes: 1 addition & 1 deletion src/ui/widgets/stack_sidebar_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ mod imp {

let mut highest_value = self.graph.get_highest_value();
if highest_value < 1.0 {
highest_value = 1.0
highest_value = 1.0;
}

self.progress_bar.set_fraction(usage / highest_value);
Expand Down
6 changes: 3 additions & 3 deletions src/ui/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ impl MainWindow {
warn!(
"Unable to update drive at {}, reason: {error}",
path.display()
)
);
}
}

Expand All @@ -365,7 +365,7 @@ impl MainWindow {
warn!(
"Unable to update network interface at {}, reason: {error}",
path.display()
)
);
}
}

Expand Down Expand Up @@ -449,7 +449,7 @@ impl MainWindow {
if let Ok(mem_data) = mem_data {
imp.memory.refresh_page(mem_data);
} else if let Err(error) = mem_data {
warn!("Unable to update memory data, reason: {error}")
warn!("Unable to update memory data, reason: {error}");
}

/*
Expand Down
20 changes: 9 additions & 11 deletions src/utils/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ static RE_FLATPAK_FILTER: Lazy<Regex> =
static DATA_DIRS: Lazy<Vec<PathBuf>> = Lazy::new(|| {
let home = std::env::var("HOME").unwrap_or_else(|_| "/".to_string());
let mut data_dirs: Vec<PathBuf> = std::env::var("XDG_DATA_DIRS")
.unwrap_or_else(|_| format!("/usr/share:{}/.local/share", home))
.unwrap_or_else(|_| format!("/usr/share:{home}/.local/share"))
.split(':')
.map(PathBuf::from)
.collect();
data_dirs.push(PathBuf::from(format!("{}/.local/share", home)));
data_dirs.push(PathBuf::from(format!("{home}/.local/share")));
data_dirs
});

Expand Down Expand Up @@ -152,7 +152,7 @@ impl App {

let apps: Vec<App> = DATA_DIRS
.iter()
.flat_map(|path| {
.filter_map(|path| {
let applications_path = path.join("applications");
let expanded_path = expanduser::expanduser(applications_path.to_string_lossy())
.unwrap_or(applications_path);
Expand Down Expand Up @@ -251,14 +251,14 @@ impl App {
let mut description_opt = None;

for locale in MESSAGE_LOCALES.iter() {
if let Some(name) = desktop_entry.get(format!("Name[{}]", locale)) {
if let Some(name) = desktop_entry.get(format!("Name[{locale}]")) {
display_name_opt = Some(name);
break;
}
}

for locale in MESSAGE_LOCALES.iter() {
if let Some(comment) = desktop_entry.get(format!("Comment[{}]", locale)) {
if let Some(comment) = desktop_entry.get(format!("Comment[{locale}]")) {
description_opt = Some(comment);
break;
}
Expand Down Expand Up @@ -552,14 +552,12 @@ impl AppsContext {
let commandline_match = app
.commandline
.as_ref()
.map(|commandline| commandline == &process.executable_path)
.unwrap_or(false);
.is_some_and(|commandline| commandline == &process.executable_path);

let executable_name_match = app
.executable_name
.as_ref()
.map(|executable_name| executable_name == &process.executable_name)
.unwrap_or(false);
.is_some_and(|executable_name| executable_name == &process.executable_name);

let known_exception_match = app
.executable_name
Expand Down Expand Up @@ -722,7 +720,7 @@ impl AppsContext {

let system_read_speed = self
.system_processes_iter()
.filter_map(|process| process.read_speed())
.filter_map(Process::read_speed)
.sum();

let system_read_total = self.read_bytes_from_dead_system_processes
Expand All @@ -733,7 +731,7 @@ impl AppsContext {

let system_write_speed = self
.system_processes_iter()
.filter_map(|process| process.write_speed())
.filter_map(Process::write_speed)
.sum();

let system_write_total = self.write_bytes_from_dead_system_processes
Expand Down
12 changes: 6 additions & 6 deletions src/utils/drive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,12 @@ impl Drive {

pub fn is_virtual(&self) -> bool {
match self.drive_type {
DriveType::LoopDevice => true,
DriveType::MappedDevice => true,
DriveType::Raid => true,
DriveType::RamDisk => true,
DriveType::ZfsVolume => true,
DriveType::Zram => true,
DriveType::LoopDevice
| DriveType::MappedDevice
| DriveType::Raid
| DriveType::RamDisk
| DriveType::ZfsVolume
| DriveType::Zram => true,
_ => self.capacity().unwrap_or(0) == 0,
}
}
Expand Down
7 changes: 2 additions & 5 deletions src/utils/gpu/amd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,11 @@ impl GpuImpl for AmdGpu {
let revision =
u8::from_str_radix(&self.read_device_file("revision")?.replace("0x", ""), 16)?;
Ok(AMDGPU_IDS
.get(&(
self.device().map(|device| device.pid()).unwrap_or(0),
revision,
))
.get(&(self.device().map_or(0, |device| device.pid()), revision))
.cloned()
.unwrap_or_else(|| {
if let Ok(drm_name) = self.drm_name() {
format!("AMD Radeon Graphics ({})", drm_name)
format!("AMD Radeon Graphics ({drm_name})")
} else {
"AMD Radeon Graphics".into()
}
Expand Down
Loading

0 comments on commit abf17cc

Please sign in to comment.