Skip to content

Commit ec6260c

Browse files
committed
Take advantage of min_exhaustive_patterns
Stabilized in Rust 1.82. I've used this pattern elsewhere for things that exit on Err variants, and I like the implicit indication that the code literally can't continue unless the result is Ok.
1 parent 291fa80 commit ec6260c

1 file changed

Lines changed: 9 additions & 13 deletions

File tree

src/main.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,12 @@ use xt::Format;
4444
mod bail;
4545

4646
fn main() {
47-
let args = match Cli::parse_args() {
48-
Ok(args) => args,
49-
Err(err) => {
50-
let mut stderr = io::stderr().lock();
51-
let _ = writeln!(stderr, "xt error: {err}");
52-
write_short_help(stderr);
53-
process::exit(2);
54-
}
55-
};
47+
let Ok(args) = Cli::parse_args().map_err(|err| {
48+
let mut stderr = io::stderr().lock();
49+
let _ = writeln!(stderr, "xt error: {err}");
50+
write_short_help(stderr);
51+
process::exit(2);
52+
});
5653

5754
let stdout = io::stdout();
5855
if stdout.is_terminal() && format_is_unsafe_for_terminal(args.to) {
@@ -71,11 +68,10 @@ fn main() {
7168
} else {
7269
InputPaths::many(args.input_pathnames.into_iter().map(Into::into))
7370
};
71+
7472
for path in input_paths {
75-
let input = match path.open() {
76-
Ok(input) => input,
77-
Err(err) => xt_bail_path!(path, "{err}"),
78-
};
73+
let Ok(input) = path.open().map_err(|err| xt_bail_path!(path, "{err}"));
74+
7975
if matches!(input, Input::Stdin) {
8076
// TODO: Is this check worth it? You can pass /dev/stdin more than once, though the
8177
// behavior might be weird.

0 commit comments

Comments
 (0)