From 9e2ea5fdd43d90b4c8cecd8e1f0354fabdbe344c Mon Sep 17 00:00:00 2001 From: Alex Novak Date: Mon, 1 Jun 2020 11:35:56 -0400 Subject: [PATCH] Incorporating feedback --- src/bin/bat/main.rs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/bin/bat/main.rs b/src/bin/bat/main.rs index c9950ae1..818b64d2 100644 --- a/src/bin/bat/main.rs +++ b/src/bin/bat/main.rs @@ -63,15 +63,15 @@ fn run_cache_subcommand(matches: &clap::ArgMatches) -> Result<()> { } fn get_syntax_mapping_to_paths( - mappings: Vec<(GlobMatcher, MappingTarget)>, + mappings: &[(GlobMatcher, MappingTarget)], ) -> HashMap> { - let mut map = HashMap::new(); + let mut map: HashMap> = HashMap::new(); for mapping in mappings { - match mapping.1 { - MappingTarget::MapToUnknown => {} - MappingTarget::MapTo(s) => { - let globs = map.entry(s.into()).or_insert(Vec::new()); - globs.push(mapping.0.glob().glob().into()); + match mapping { + (_, MappingTarget::MapToUnknown) => {} + (matcher, MappingTarget::MapTo(s)) => { + let globs = map.entry((*s).into()).or_insert(Vec::new()); + globs.push(matcher.glob().glob().into()); } } } @@ -88,14 +88,15 @@ pub fn list_languages(config: &Config) -> Result<()> { .collect::>(); languages.sort_by_key(|lang| lang.name.to_uppercase()); - let configured_languages = - get_syntax_mapping_to_paths(config.syntax_mapping.mappings().clone()); + let configured_languages = get_syntax_mapping_to_paths(config.syntax_mapping.mappings()); for lang in languages.iter_mut() { - if configured_languages.contains_key(&lang.name) { - let additional_paths = configured_languages.get(&lang.name).unwrap(); - lang.file_extensions - .extend(additional_paths.iter().cloned()); + match configured_languages.get(&lang.name) { + Some(additional_paths) => { + lang.file_extensions + .extend(additional_paths.iter().cloned()); + } + None => {} } }