From 2f79b4db0396c32d8ff3bada79da1ea1a262d84f Mon Sep 17 00:00:00 2001 From: Benjamin Sago Date: Thu, 18 May 2017 22:43:32 +0100 Subject: [PATCH] Start using new shorthand object field syntax --- src/exa.rs | 6 ++---- src/options/dir_action.rs | 5 +---- src/options/mod.rs | 6 +----- src/options/view.rs | 28 +++++++++------------------- src/output/details.rs | 9 +-------- src/output/file_name.rs | 12 +++--------- 6 files changed, 17 insertions(+), 49 deletions(-) diff --git a/src/exa.rs b/src/exa.rs index e7a88f3..096389f 100644 --- a/src/exa.rs +++ b/src/exa.rs @@ -55,10 +55,8 @@ pub struct Exa<'w, W: Write + 'w> { impl<'w, W: Write + 'w> Exa<'w, W> { pub fn new(args: &[S], writer: &'w mut W) -> Result, Misfire> where S: AsRef { - Options::getopts(args).map(move |(opts, args)| Exa { - options: opts, - writer: writer, - args: args, + Options::getopts(args).map(move |(options, args)| { + Exa { options, writer, args } }) } diff --git a/src/options/dir_action.rs b/src/options/dir_action.rs index d6fa993..6c2aae2 100644 --- a/src/options/dir_action.rs +++ b/src/options/dir_action.rs @@ -89,10 +89,7 @@ impl RecurseOptions { None }; - Ok(RecurseOptions { - tree: tree, - max_depth: max_depth, - }) + Ok(RecurseOptions { tree, max_depth }) } /// Returns whether a directory of the given depth would be too deep. diff --git a/src/options/mod.rs b/src/options/mod.rs index b59ce78..daebb3d 100644 --- a/src/options/mod.rs +++ b/src/options/mod.rs @@ -143,11 +143,7 @@ impl Options { let filter = FileFilter::deduce(matches)?; let view = View::deduce(matches, filter.clone(), dir_action)?; - Ok(Options { - dir_action: dir_action, - view: view, - filter: filter, // TODO: clone - }) + Ok(Options { dir_action, view, filter }) } } diff --git a/src/options/view.rs b/src/options/view.rs index e3dfceb..184a534 100644 --- a/src/options/view.rs +++ b/src/options/view.rs @@ -94,9 +94,9 @@ impl View { if let Some(&width) = term_width.as_ref() { let colours = match term_colours { - TerminalColours::Always - | TerminalColours::Automatic => Colours::colourful(colour_scale()), - TerminalColours::Never => Colours::plain(), + TerminalColours::Always | + TerminalColours::Automatic => Colours::colourful(colour_scale()), + TerminalColours::Never => Colours::plain(), }; if matches.opt_present("oneline") { @@ -104,12 +104,7 @@ impl View { Err(Useless("across", true, "oneline")) } else { - let lines = Lines { - colours: colours, - classify: classify, - }; - - Ok(View::Lines(lines)) + Ok(View::Lines(Lines { colours, classify })) } } else if matches.opt_present("tree") { @@ -160,28 +155,23 @@ impl View { Ok(View::Details(details)) } else { - let lines = Lines { - colours: colours, - classify: classify, - }; - - Ok(View::Lines(lines)) + Ok(View::Lines(Lines { colours, classify })) } } }; if matches.opt_present("long") { - let long_options = long()?; + let details = long()?; if matches.opt_present("grid") { match other_options_scan() { - Ok(View::Grid(grid)) => return Ok(View::GridDetails(GridDetails { grid: grid, details: long_options })), + Ok(View::Grid(grid)) => return Ok(View::GridDetails(GridDetails { grid, details })), Ok(lines) => return Ok(lines), Err(e) => return Err(e), }; } else { - return Ok(View::Details(long_options)); + return Ok(View::Details(details)); } } @@ -313,7 +303,7 @@ impl TimeTypes { } } else if modified || created || accessed { - Ok(TimeTypes { accessed: accessed, modified: modified, created: created }) + Ok(TimeTypes { accessed, modified, created }) } else { Ok(TimeTypes::default()) diff --git a/src/output/details.rs b/src/output/details.rs index 1605bb1..fbd7059 100644 --- a/src/output/details.rs +++ b/src/output/details.rs @@ -316,14 +316,7 @@ impl Details { } }; - let egg = Egg { - cells: cells, - xattrs: xattrs, - errors: errors, - dir: dir, - file: file, - }; - + let egg = Egg { cells, xattrs, errors, dir, file }; file_eggs.lock().unwrap().push(egg); }); } diff --git a/src/output/file_name.rs b/src/output/file_name.rs index ebe4271..1ba0fed 100644 --- a/src/output/file_name.rs +++ b/src/output/file_name.rs @@ -34,15 +34,9 @@ impl<'a, 'dir> FileName<'a, 'dir> { /// Create a new `FileName` that prints the given file’s name, painting it /// with the remaining arguments. pub fn new(file: &'a File<'dir>, link_style: LinkStyle, classify: Classify, colours: &'a Colours) -> FileName<'a, 'dir> { - let target = if file.is_link() { Some(file.link_target()) } - else { None }; - FileName { - file: file, - colours: colours, - target: target, - link_style: link_style, - classify: classify, - } + let target = if file.is_link() { Some(file.link_target()) } + else { None }; + FileName { file, colours, target, link_style, classify } }