From 2ad18488597e98e55e924321c843653ee4274f39 Mon Sep 17 00:00:00 2001 From: sharkdp Date: Sat, 11 Apr 2020 19:23:32 +0200 Subject: [PATCH] Do not take optional as argument --- src/bin/bat/app.rs | 18 ++++++++---------- src/inputfile.rs | 7 ++----- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs index 2da8a0d1..cbea5f3e 100644 --- a/src/bin/bat/app.rs +++ b/src/bin/bat/app.rs @@ -260,17 +260,15 @@ impl App { let mut file_input = Vec::new(); for (input, name) in files_or_none.zip(filenames_or_none) { - match input { - Some(input) => { - if input.to_str().unwrap() == "-" { - file_input.push(InputFile::StdIn(name)); - } else { - file_input.push(InputFile::Ordinary(OrdinaryFile::from_path_with_name( - input, name, - ))) - } + if let Some(input) = input { + if input.to_str().unwrap() == "-" { + file_input.push(InputFile::StdIn(name)); + } else { + let ofile = name.map_or(OrdinaryFile::from_path(input), |n| { + OrdinaryFile::from_path_with_name(input, n) + }); + file_input.push(InputFile::Ordinary(ofile)) } - None => {} } } return Ok(file_input); diff --git a/src/inputfile.rs b/src/inputfile.rs index 0e4b8e28..4e342cca 100644 --- a/src/inputfile.rs +++ b/src/inputfile.rs @@ -66,13 +66,10 @@ impl<'a> OrdinaryFile<'a> { } } - pub fn from_path_with_name( - path: &'a OsStr, - user_provided_name: Option<&'a OsStr>, - ) -> OrdinaryFile<'a> { + pub fn from_path_with_name(path: &'a OsStr, user_provided_name: &'a OsStr) -> OrdinaryFile<'a> { OrdinaryFile { path, - user_provided_name, + user_provided_name: Some(user_provided_name), } }