Fix clippy warnings
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by sharkdp · committed by sharkdp · parent 1430c1d · Browse files · 2 files·+30 added−31 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+30 added−31 removed
- other:+30 added−31 removed
Provenance
- Commit
787e459- Tree
9fd9e73- Author
sharkdp <davidpeter@web.de>- Committer
sharkdp <davidpeter@web.de>- Parent
1430c1d
2 files changed+30 added−31 removed
modified:src/bin/main.rs+7 added-8 removed
10 unmodified lines11 use std::io::Write;12 use std::path::{Path, Component};13 use std::process;14 15-use ansi_term::Style;15 use getopts::Options;16 use isatty::stdout_isatty;17 use regex::{Regex, RegexBuilder};18 use ignore::WalkBuilder;49 unmodified lines68 .and_then(|n| n.to_str())69 .and_then(|n| config.ls_colors.filenames.get(n));70 71 match o_style {73- Some(s) => s.clone(),72+ Some(s) => *s,73 None =>74 // Look up file extension75 component_path.extension()76 .and_then(|e| e.to_str())77 .and_then(|e| config.ls_colors.extensions.get(e))79- .map(|r| r.clone())80- .unwrap_or(Style::new())78+ .cloned()79+ .unwrap_or_default()80 }81 };82 83 print!("{}", style.paint(comp_str.to_str().unwrap()));38 unmodified lines122 .and_then(OsStr::to_str)123 };124 125 search_str.and_then(|s| pattern.find(s))127- .map(|_| print_entry(&root, path_rel, &config));126+ .map(|_| print_entry(root, path_rel, config));127 }128 }129 130 /// Print error message to stderr and exit with status `1`.30 unmodified lines161 };162 163 if matches.opt_present("h") {164 let brief = "Usage: fd [options] [PATTERN]";166- print!("{}", opts.usage(&brief));165+ print!("{}", opts.usage(brief));166 process::exit(1);167 }168 169 let empty = String::new();11 unmodified lines181 let ls_colors =182 env::var("LS_COLORS")183 .ok()184 .map(|val| LsColors::from_string(&val))186- .unwrap_or(LsColors::default());185+ .unwrap_or_default();186 187 let config = FdOptions {188 // The search will be case-sensitive if the command line flag is set or189 // if the pattern has an uppercase character (smart case).12 unmodified lines202 203 match RegexBuilder::new(pattern)204 .case_insensitive(!config.case_sensitive)205 .build() {207- Ok(re) => scan(¤t_dir, &re, &config),206+ Ok(re) => scan(current_dir, &re, &config),207 Err(err) => error(err.description())208 }209 }modified:src/lscolors/mod.rs+23 added-23 removed
20 unmodified lines21 pub extensions: ExtensionStyles,22 pub filenames: FilenameStyles,23 }24 25-impl LsColors {25+impl Default for LsColors {26 /// Get a default LsColors structure.27- pub fn default() -> LsColors {27+ fn default() -> LsColors {28 LsColors {29 directory: Colour::Blue.bold(),30 symlink: Colour::Cyan.normal(),31 extensions: HashMap::new(),32 filenames: HashMap::new()33 }34 }35+}36 37+impl LsColors {38 fn parse_decoration(code: &str) -> Option<fn(Colour) -> Style> {39 match code {40 "0" | "00" => Some(Colour::normal),41 "1" | "01" => Some(Colour::bold),4 unmodified lines46 }47 48 /// Parse ANSI escape sequences like `38;5;10;1`.49 fn parse_style(code: &str) -> Option<Style> {48- let mut split = code.split(";");50+ let mut split = code.split(';');51 52 if let Some(first) = split.next() {53 // Try to match the first part as a text-decoration argument54 let mut decoration = LsColors::parse_decoration(first);11 unmodified lines66 n_white67 };68 69 Colour::Fixed(n)68- } else {69- if let Some(color_s) = c1 {70- match color_s {71- "30" => Colour::Black,72- "31" => Colour::Red,73- "32" => Colour::Green,74- "33" => Colour::Yellow,75- "34" => Colour::Blue,76- "35" => Colour::Purple,77- "36" => Colour::Cyan,78- _ => Colour::White70+ } else if let Some(color_s) = c1 {71+ match color_s {72+ "30" => Colour::Black,73+ "31" => Colour::Red,74+ "32" => Colour::Green,75+ "33" => Colour::Yellow,76+ "34" => Colour::Blue,77+ "35" => Colour::Purple,78+ "36" => Colour::Cyan,79+ _ => Colour::White79- }80- } else {81- Colour::White80 }81+ } else {82+ Colour::White83 };84 85 if decoration.is_none() {86 // Try to find a decoration somewhere in the sequence87- decoration = code.split(";")87+ decoration = code.split(';')88 .flat_map(LsColors::parse_decoration)89 .next();90 }91 6 unmodified lines98 }99 100 /// Add a new LS_COLORS entry101 fn add_entry(&mut self, input: &str) {102- let mut parts = input.trim().split("=");102+ let mut parts = input.trim().split('=');103 if let Some(pattern) = parts.next() {104 if let Some(style_code) = parts.next() {105 // Ensure that the input was split into exactly two parts:106 if !parts.next().is_none() {13 unmodified lines120 } else if pattern.starts_with("*.") {121 let extension = String::from(pattern).split_off(2);122 self.extensions.insert(extension, style);123 }124- else if pattern.starts_with("*") {124+ else if pattern.starts_with('*') {125 let filename = String::from(pattern).split_off(1);126 self.filenames.insert(filename, style);127 } else {128 // Unknown/corrupt pattern4 unmodified lines133 }134 }135 136 /// Generate a `LsColors` structure from a string.137- pub fn from_string(input: &String) -> LsColors {137+ pub fn from_string(input: &str) -> LsColors {138 let mut lscolors = LsColors::default();139 140- for s in input.split(":") {141- lscolors.add_entry(&s);140+ for s in input.split(':') {141+ lscolors.add_entry(s);142 }143 144 lscolors145 }59 unmodified lines