Skip to content

Commit ddfc5c8

Browse files
committed
Collapse if-let statements
1 parent f1a7238 commit ddfc5c8

File tree

5 files changed

+20
-37
lines changed

5 files changed

+20
-37
lines changed

src/blocks/amd_gpu.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,9 @@ impl Device {
144144
let mut path = entry.path();
145145
path.push("device");
146146

147-
let Ok(uevent) = read_file(path.join("uevent")).await else {
148-
continue;
149-
};
150-
151-
if uevent.contains("PCI_ID=1002") {
147+
if let Ok(uevent) = read_file(path.join("uevent")).await
148+
&& uevent.contains("PCI_ID=1002")
149+
{
152150
return Ok(Some(Self { path }));
153151
}
154152
}

src/blocks/memory.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -357,14 +357,11 @@ impl Memstate {
357357
}
358358

359359
let mut values = line.split_whitespace().map(|s| s.parse::<u64>());
360-
let (Some(Ok(zram_swap_size)), Some(Ok(zram_comp_size))) =
360+
if let (Some(Ok(zram_swap_size)), Some(Ok(zram_comp_size))) =
361361
(values.next(), values.next())
362-
else {
363-
continue;
364-
};
365-
366-
// zram initializes with small amount by default, return 0 then
367-
if zram_swap_size >= 65_536 {
362+
// zram initializes with small amount by default, return 0 then
363+
&& zram_swap_size >= 65_536
364+
{
368365
mem_state.zram_decompressed += zram_swap_size;
369366
mem_state.zram_compressed += zram_comp_size;
370367
}

src/blocks/privacy/pipewire.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,10 @@ impl PrivacyMonitor for Monitor<'_> {
221221
..
222222
} in data.links.values().sorted().dedup()
223223
{
224-
let (Some(output_node), Some(input_node)) = (
224+
if let (Some(output_node), Some(input_node)) = (
225225
data.nodes.get(link_output_node),
226226
data.nodes.get(link_input_node),
227-
) else {
228-
continue;
229-
};
230-
if input_node.media_class != Some("Audio/Sink".into())
227+
) && input_node.media_class != Some("Audio/Sink".into())
231228
&& !self.config.exclude_output.contains(&output_node.name)
232229
&& !self.config.exclude_input.contains(&input_node.name)
233230
{

src/blocks/privacy/v4l.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,10 @@ impl PrivacyMonitor for Monitor<'_> {
108108
continue;
109109
};
110110
while let Ok(Some(fd_path)) = fd_paths.next_entry().await {
111-
let Ok(link_path) = fd_path.path().read_link() else {
112-
continue;
113-
};
114-
if self.devices.contains_key(&link_path) {
115-
let Ok(mut file) = File::open(proc_path.join("comm")).await else {
116-
continue;
117-
};
111+
if let Ok(link_path) = fd_path.path().read_link()
112+
&& self.devices.contains_key(&link_path)
113+
&& let Ok(mut file) = File::open(proc_path.join("comm")).await
114+
{
118115
let mut contents = String::new();
119116
if file.read_to_string(&mut contents).await.is_ok() {
120117
let reader = contents.trim_end().to_string();

src/netlink.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,10 @@ impl WifiInfo {
166166
.error("Failed to get nl80211 interfaces")?;
167167

168168
for interface in interfaces {
169-
if let Some(index) = interface.index {
170-
if index != if_index {
171-
continue;
172-
}
173-
174-
let Ok(ap) = socket.get_station_info(index).await else {
175-
continue;
176-
};
177-
169+
if let Some(index) = interface.index
170+
&& index == if_index
171+
&& let Ok(ap) = socket.get_station_info(index).await
172+
{
178173
// TODO: are there any situations when there is more than one station?
179174
let Some(ap) = ap.into_iter().next() else {
180175
continue;
@@ -413,11 +408,10 @@ async fn ip_payload<const BYTES: usize>(
413408

414409
let attr_handle = msg.rtattrs.get_attr_handle();
415410

416-
let Some(attr) = attr_handle.get_attribute(Ifa::Local)
411+
if let Some(attr) = attr_handle.get_attribute(Ifa::Local)
417412
.or_else(|| attr_handle.get_attribute(Ifa::Address))
418-
else { continue };
419-
420-
if let Ok(p) = attr.rta_payload.as_ref().try_into() {
413+
&& let Ok(p) = attr.rta_payload.as_ref().try_into()
414+
{
421415
payload = Some(p);
422416
}
423417
});

0 commit comments

Comments
 (0)