Repository: sharkdp/bat
File: src/bin/bat/main.rs (Rust)

Code before:
};

fn run_cache_subcommand(matches: &clap::ArgMatches) -> Result<()> {
    if matches.is_present("build") {
        let source_dir = matches
            .value_of("source")
            .map(Path::new)
            .unwrap_or_else(|| PROJECT_DIRS.config_dir());
        let target_dir = matches
            .value_of("target")
            .map(Path::new)
            .unwrap_or_else(|| PROJECT_DIRS.cache_dir());

        let blank = matches.is_present("blank");

        let assets = HighlightingAssets::from_files(source_dir, !blank)?;
        assets.save_to_cache(target_dir, crate_version!())?;
    } else if matches.is_present("clear") {
        clear_assets();
    }

    Ok(())
}

fn get_syntax_mapping_to_paths(
    mappings: Vec<(GlobMatcher, MappingTarget)>,
) -> HashMap<String, Vec<String>> {
    let mut map = 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());
            }
        }
    }
    map
}

pub fn list_languages(config: &Config) -> Result<()> {
    let assets = assets_from_cache_or_binary()?;
    let mut languages = assets
        .syntaxes()
        .iter()
        .filter(|syntax| !syntax.hidden && !syntax.file_extensions.is_empty())
        .cloned()
        .collect::<Vec<_>>();
    languages.sort_by_key(|lang| lang.name.to_uppercase());

    let configured_languages =

Review comment (suggestion):
you are taking the whole vector *by value*. This is why you have to call `.clone` below. You can avoid this by taking `mappings` as a `&[(GlobMatcher, MappingTarget)]` argument.

Code after:
    MappingTarget,
};

const THEME_PREVIEW_DATA: &[u8] = include_bytes!("../../../assets/theme_preview.rs");

fn run_cache_subcommand(matches: &clap::ArgMatches) -> Result<()> {
    if matches.is_present("build") {
        let source_dir = matches
            .value_of("source")
            .map(Path::new)
            .unwrap_or_else(|| PROJECT_DIRS.config_dir());
        let target_dir = matches
            .value_of("target")
            .map(Path::new)
            .unwrap_or_else(|| PROJECT_DIRS.cache_dir());

        let blank = matches.is_present("blank");

        let assets = HighlightingAssets::from_files(source_dir, !blank)?;
        assets.save_to_cache(target_dir, crate_version!())?;
    } else if matches.is_present("clear") {
        clear_assets();
    }

    Ok(())
}

fn get_syntax_mapping_to_paths<'a>(
    mappings: &[(GlobMatcher, MappingTarget<'a>)],
) -> HashMap<&'a str, Vec<String>> {
    let mut map = HashMap::new();
    for mapping in mappings {
        match mapping {
            (_, MappingTarget::MapToUnknown) => {}
            (matcher, MappingTarget::MapTo(s)) => {
                let globs = map.entry(*s).or_insert_with(Vec::new);
                globs.push(matcher.glob().glob().into());
            }
        }
    }
    map
}

pub fn list_languages(config: &Config) -> Result<()> {
    let assets = assets_from_cache_or_binary()?;
    let mut languages = assets
        .syntaxes()
        .iter()
        .filter(|syntax| !syntax.hidden && !syntax.file_extensions.is_empty())
        .cloned()
        .collect::<Vec<_>>();