on master help sign in
Do not take optional as argument
commit2ad18488597e98e55e924321c843653ee4274f39 authorsharkdp <davidpeter@web.de> dateSat 11 Apr 2020, 19:23 (7 years ago) parent90e7d2f
2 files changed+10−15
src/bin/bat/app.rs+8−10 src/inputfile.rs+2−5
src/bin/bat/app.rs+8−10
@@ -260,17 +260,15 @@ impl App {
260260
261261 let mut file_input = Vec::new();
262262 for (input, name) in files_or_none.zip(filenames_or_none) {
263− match input {
264− Some(input) => {
265− if input.to_str().unwrap() == "-" {
266− file_input.push(InputFile::StdIn(name));
267− } else {
268− file_input.push(InputFile::Ordinary(OrdinaryFile::from_path_with_name(
269− input, name,
270− )))
271− }
263+ if let Some(input) = input {
264+ if input.to_str().unwrap() == "-" {
265+ file_input.push(InputFile::StdIn(name));
266+ } else {
267+ let ofile = name.map_or(OrdinaryFile::from_path(input), |n| {
268+ OrdinaryFile::from_path_with_name(input, n)
269+ });
270+ file_input.push(InputFile::Ordinary(ofile))
272271 }
273− None => {}
274272 }
275273 }
276274 return Ok(file_input);
src/inputfile.rs+2−5
@@ -66,13 +66,10 @@ impl<'a> OrdinaryFile<'a> {
6666 }
6767 }
6868
69− pub fn from_path_with_name(
70− path: &'a OsStr,
71− user_provided_name: Option<&'a OsStr>,
72− ) -> OrdinaryFile<'a> {
69+ pub fn from_path_with_name(path: &'a OsStr, user_provided_name: &'a OsStr) -> OrdinaryFile<'a> {
7370 OrdinaryFile {
7471 path,
75− user_provided_name,
72+ user_provided_name: Some(user_provided_name),
7673 }
7774 }
7875