From c8d4ec89a3be045a5ce2fdc7af54bf383b8d4645 Mon Sep 17 00:00:00 2001 From: sharkdp Date: Fri, 9 Jun 2017 14:39:57 +0200 Subject: [PATCH] Use references instead of values --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 13 +++++++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 19f0052..090f9b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ [root] name = "fd" -version = "1.0.0" +version = "1.1.0" dependencies = [ "ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 0f7e4fb..1b2fec6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fd" -version = "1.0.0" +version = "1.1.0" authors = ["David Peter "] [dependencies] diff --git a/src/main.rs b/src/main.rs index 1aa736a..b2b8836 100644 --- a/src/main.rs +++ b/src/main.rs @@ -90,6 +90,8 @@ fn print_entry(base: &Path, entry: &Path, config: &FdOptions) { let is_executable = |p: &std::path::PathBuf| {false}; if let Some(ref ls_colors) = config.ls_colors { + let default_style = ansi_term::Style::default(); + let mut component_path = base.to_path_buf(); if config.path_display == PathDisplay::Absolute { @@ -110,11 +112,11 @@ fn print_entry(base: &Path, entry: &Path, config: &FdOptions) { if component_path.symlink_metadata() .map(|md| md.file_type().is_symlink()) .unwrap_or(false) { - ls_colors.symlink + &ls_colors.symlink } else if component_path.is_dir() { - ls_colors.directory + &ls_colors.directory } else if is_executable(&component_path) { - ls_colors.executable + &ls_colors.executable } else { // Look up file name let o_style = @@ -123,14 +125,13 @@ fn print_entry(base: &Path, entry: &Path, config: &FdOptions) { .and_then(|n| ls_colors.filenames.get(n)); match o_style { - Some(s) => *s, + Some(s) => s, None => // Look up file extension component_path.extension() .and_then(|e| e.to_str()) .and_then(|e| ls_colors.extensions.get(e)) - .cloned() - .unwrap_or_default() + .unwrap_or(&default_style) } };