Skip to content

Commit db4afdf

Browse files
committed
De-tuple if-let statements
1 parent ddfc5c8 commit db4afdf

File tree

8 files changed

+39
-37
lines changed

8 files changed

+39
-37
lines changed

build.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ fn main() {
1111
.env("GIT_CONFIG_GLOBAL", "/dev/null")
1212
.output()
1313
.map(|o| String::from_utf8(o.stdout).unwrap());
14-
if let (Ok(hash), Ok(date)) = (hash, date) {
14+
if let Ok(hash) = hash
15+
&& let Ok(date) = date
16+
{
1517
let ver = format!(
1618
"{} (commit {} {})",
1719
env!("CARGO_PKG_VERSION"),

src/blocks/calendar.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,8 @@ pub async fn run(config: &Config, api: &CommonApi) -> Result<()> {
360360
}
361361

362362
if let Some(event) = next_events.current().cloned()
363-
&& let (Some(start_date), Some(end_date)) = (event.start_at, event.end_at)
363+
&& let Some(start_date) = event.start_at
364+
&& let Some(end_date) = event.end_at
364365
{
365366
let warn_datetime = start_date - warning_threshold;
366367
if warn_datetime < Utc::now() && Utc::now() < start_date {

src/blocks/memory.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,7 @@ impl Memstate {
357357
}
358358

359359
let mut values = line.split_whitespace().map(|s| s.parse::<u64>());
360-
if let (Some(Ok(zram_swap_size)), Some(Ok(zram_comp_size))) =
361-
(values.next(), values.next())
360+
if let Some(Ok(zram_swap_size)) = values.next() && let Some(Ok(zram_comp_size)) = values.next()
362361
// zram initializes with small amount by default, return 0 then
363362
&& zram_swap_size >= 65_536
364363
{

src/blocks/privacy/pipewire.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,13 @@ struct Link {
4848

4949
impl Link {
5050
fn new(global_props: &DictRef) -> Option<Self> {
51-
if let (Some(link_output_node), Some(link_input_node)) = (
52-
global_props
53-
.get(&keys::LINK_OUTPUT_NODE)
54-
.and_then(|s| s.parse().ok()),
55-
global_props
51+
if let Some(link_output_node) = global_props
52+
.get(&keys::LINK_OUTPUT_NODE)
53+
.and_then(|s| s.parse().ok())
54+
&& let Some(link_input_node) = global_props
5655
.get(&keys::LINK_INPUT_NODE)
57-
.and_then(|s| s.parse().ok()),
58-
) {
56+
.and_then(|s| s.parse().ok())
57+
{
5958
Some(Self {
6059
link_output_node,
6160
link_input_node,
@@ -221,10 +220,9 @@ impl PrivacyMonitor for Monitor<'_> {
221220
..
222221
} in data.links.values().sorted().dedup()
223222
{
224-
if let (Some(output_node), Some(input_node)) = (
225-
data.nodes.get(link_output_node),
226-
data.nodes.get(link_input_node),
227-
) && input_node.media_class != Some("Audio/Sink".into())
223+
if let Some(output_node) = data.nodes.get(link_output_node)
224+
&& let Some(input_node) = data.nodes.get(link_input_node)
225+
&& input_node.media_class != Some("Audio/Sink".into())
228226
&& !self.config.exclude_output.contains(&output_node.name)
229227
&& !self.config.exclude_input.contains(&input_node.name)
230228
{

src/blocks/privacy/v4l.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -108,26 +108,25 @@ impl PrivacyMonitor for Monitor<'_> {
108108
continue;
109109
};
110110
while let Ok(Some(fd_path)) = fd_paths.next_entry().await {
111+
let mut contents = String::new();
111112
if let Ok(link_path) = fd_path.path().read_link()
112113
&& self.devices.contains_key(&link_path)
113114
&& let Ok(mut file) = File::open(proc_path.join("comm")).await
115+
&& file.read_to_string(&mut contents).await.is_ok()
114116
{
115-
let mut contents = String::new();
116-
if file.read_to_string(&mut contents).await.is_ok() {
117-
let reader = contents.trim_end().to_string();
118-
if self.config.exclude_consumer.contains(&reader) {
119-
continue;
120-
}
121-
debug!("{} {:?}", reader, link_path);
122-
*mapping
123-
.entry(Type::Webcam)
124-
.or_default()
125-
.entry(link_path.to_string_lossy().to_string())
126-
.or_default()
127-
.entry(reader)
128-
.or_default() += 1;
129-
debug!("{:?}", mapping);
117+
let reader = contents.trim_end().to_string();
118+
if self.config.exclude_consumer.contains(&reader) {
119+
continue;
130120
}
121+
debug!("{} {:?}", reader, link_path);
122+
*mapping
123+
.entry(Type::Webcam)
124+
.or_default()
125+
.entry(link_path.to_string_lossy().to_string())
126+
.or_default()
127+
.entry(reader)
128+
.or_default() += 1;
129+
debug!("{:?}", mapping);
131130
}
132131
}
133132
}

src/blocks/weather.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,9 @@ impl Forecast {
375375
humidity_count += 1.0;
376376
}
377377

378-
if let (Some(wind), Some(wind_kmh)) = (val.wind, val.wind_kmh) {
378+
if let Some(wind) = val.wind
379+
&& let Some(wind_kmh) = val.wind_kmh
380+
{
379381
if let Some(degrees) = val.wind_direction {
380382
let (sin, cos) = degrees.to_radians().sin_cos();
381383
wind_north_avg += wind * cos;

src/blocks/weather/met_no.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,10 @@ impl ForecastTimeStep {
113113
fn to_aggregate(&self) -> ForecastAggregateSegment {
114114
let instant = &self.data.instant.details;
115115

116-
let apparent = if let (Some(air_temperature), Some(relative_humidity), Some(wind_speed)) = (
117-
instant.air_temperature,
118-
instant.relative_humidity,
119-
instant.wind_speed,
120-
) {
116+
let apparent = if let Some(air_temperature) = instant.air_temperature
117+
&& let Some(relative_humidity) = instant.relative_humidity
118+
&& let Some(wind_speed) = instant.wind_speed
119+
{
121120
Some(australian_apparent_temp(
122121
air_temperature,
123122
relative_humidity,

src/blocks/xrandr.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ async fn get_monitors() -> Result<Vec<Monitor>> {
170170

171171
let mut it = monitors_info.lines().filter(|line| regex.is_match(line));
172172

173-
while let (Some(line1), Some(line2)) = (it.next(), it.next()) {
173+
while let Some(line1) = it.next()
174+
&& let Some(line2) = it.next()
175+
{
174176
let mut tokens = line1.split_ascii_whitespace().peekable();
175177
let name = tokens.next().error("Failed to parse xrandr output")?.into();
176178
let _ = tokens.next();

0 commit comments

Comments
 (0)