Skip to content

Commit 25ea29f

Browse files
author
damon
committed
fix: resolve option_if_let_else clippy lint on stable 1.93
Lint graduated from nursery to stable; apply map_or_else in 3 spots.
1 parent fbd0f97 commit 25ea29f

4 files changed

Lines changed: 19 additions & 21 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,22 +101,23 @@ fn main() {
101101
}
102102
}
103103

104-
let buf: Vec<u8> = if let Some(path) = &file {
105-
match std::fs::read(path) {
104+
let buf: Vec<u8> = file.as_ref().map_or_else(
105+
|| {
106+
let mut buf = Vec::new();
107+
if let Err(e) = io::stdin().read_to_end(&mut buf) {
108+
eprintln!("batdoc: stdin: {e}");
109+
process::exit(1);
110+
}
111+
buf
112+
},
113+
|path| match std::fs::read(path) {
106114
Ok(b) => b,
107115
Err(e) => {
108116
eprintln!("batdoc: {path}: {e}");
109117
process::exit(1);
110118
}
111-
}
112-
} else {
113-
let mut buf = Vec::new();
114-
if let Err(e) = io::stdin().read_to_end(&mut buf) {
115-
eprintln!("batdoc: stdin: {e}");
116-
process::exit(1);
117-
}
118-
buf
119-
};
119+
},
120+
);
120121

121122
if buf.len() > MAX_INPUT_SIZE {
122123
#[allow(clippy::cast_precision_loss)] // only used in error message

src/sheet.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,7 @@ fn strip_trailing_empty_rows(rows: &[Vec<String>]) -> Vec<Vec<String>> {
122122
let last_nonempty = rows
123123
.iter()
124124
.rposition(|row| row.iter().any(|cell| !cell.trim().is_empty()));
125-
match last_nonempty {
126-
Some(idx) => rows[..=idx].to_vec(),
127-
None => Vec::new(),
128-
}
125+
last_nonempty.map_or_else(Vec::new, |idx| rows[..=idx].to_vec())
129126
}
130127

131128
/// Strip leading and trailing columns that are entirely empty.

src/xlsx.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,11 @@ fn parse_cell(reader: &mut Reader<&[u8]>, cell_type: &str, shared_strings: &[Str
296296
match cell_type {
297297
"s" => {
298298
// Shared string reference
299-
if let Ok(idx) = value.parse::<usize>() {
300-
shared_strings.get(idx).cloned().unwrap_or_default()
301-
} else {
302-
String::new()
303-
}
299+
value
300+
.parse::<usize>()
301+
.ok()
302+
.and_then(|idx| shared_strings.get(idx).cloned())
303+
.unwrap_or_default()
304304
}
305305
"inlineStr" => inline_text,
306306
_ => value, // numbers, booleans, formula cached values, etc.

0 commit comments

Comments
 (0)