fn parse_regions<T: AsRef<str>>(region_str: T) -> Vec<Region> {
    let good_tools_try = from_goodtools_region(&region_str.as_ref())
        .map(|(_, res)| res)
        .unwrap_or(vec![Region::Unknown]);
    let nointro_try = from_nointro_region(&region_str.as_ref())
        .map(|(_, res)| res)
        .unwrap_or(vec![Region::Unknown]);
    let tosec_try = from_tosec_region(&region_str.as_ref())
        .map(|(_, res)| res)
        .unwrap_or(vec![Region::Unknown]);
    // thanks @Rantanen on the Rust discord
    array::IntoIter::new([good_tools_try, nointro_try, tosec_try])
        // Precalculate all the counts so they don't need to be calculated for
        // every single comparison.
        .map(|v| (v.iter().filter(|&r| *r != Region::Unknown).count(), v))
        // Use the count as the key to get max by.
        .max_by_key(|(count, _)| *count)
        // Map the (count, vec) tuple back to the vec.
        // The count has served its purpose.
        .map(|(_, v)| v)
        // In case the option was none (the input Vec was empty), return empty vec.
        .unwrap_or_else(|| vec![Region::Unknown])
}
/// Best-guess a region string from one of the three known formats.
/// Returns the format that matches the best (meaning it contains the longest number of matches, excluding 'Unknown')
/// This function expects that the input string is a valid GoodTools, No-Intro, or TOSEC region string.
/// If no match can be found, returns unknown region.
Best-guess a region string from one of the three known formats.
Returns the format that matches the best (meaning it contains the longest number of matches, excluding 'Unknown')
This function expects that the input string is a valid GoodTools, No-Intro, or TOSEC region string.
If no match can be found, returns unknown region.
Best - guess a region string from one of the three known formats . Returns the format that matches the best ( meaning it contains the longest number of matches excluding ' Unknown ' ) This function expects that the input string is a valid GoodTools No - Intro or TOSEC region string . If no match can be found returns unknown region .
fn parse_regions<T: AsRef<str>>(region_str: T) -> Vec<Region> {
    let good_tools_try = from_goodtools_region(&region_str.as_ref())
        .map(|(_, res)| res)
        .unwrap_or(vec![Region::Unknown]);
    let nointro_try = from_nointro_region(&region_str.as_ref())
        .map(|(_, res)| res)
        .unwrap_or(vec![Region::Unknown]);
    let tosec_try = from_tosec_region(&region_str.as_ref())
        .map(|(_, res)| res)
        .unwrap_or(vec![Region::Unknown]);
    // thanks @Rantanen on the Rust discord
    array::IntoIter::new([good_tools_try, nointro_try, tosec_try])
        // Precalculate all the counts so they don't need to be calculated for
        // every single comparison.
        .map(|v| (v.iter().filter(|&r| *r != Region::Unknown).count(), v))
        // Use the count as the key to get max by.
        .max_by_key(|(count, _)| *count)
        // Map the (count, vec) tuple back to the vec.
        // The count has served its purpose.
        .map(|(_, v)| v)
        // In case the option was none (the input Vec was empty), return empty vec.
        .unwrap_or_else(|| vec![Region::Unknown])
}
fn parse_regions < T : AsRef < str > > ( region_str : T ) -> Vec < Region > { let good_tools_try = from_goodtools_region ( & region_str . as_ref ( ) ) . map ( | ( _ , res ) | res ) . unwrap_or ( vec ! [ Region Unknown ] ) ; let nointro_try = from_nointro_region ( & region_str . as_ref ( ) ) . map ( | ( _ , res ) | res ) . unwrap_or ( vec ! [ Region Unknown ] ) ; let tosec_try = from_tosec_region ( & region_str . as_ref ( ) ) . map ( | ( _ , res ) | res ) . unwrap_or ( vec ! [ Region Unknown ] ) ; // thanks @Rantanen on the Rust discord array :: IntoIter :: new ( [ good_tools_try , nointro_try , tosec_try ] ) // Precalculate all the counts so they don't need to be calculated for // every single comparison. . map ( | v | ( v . iter ( ) . filter ( | & r | * r != Region :: Unknown ) . count ( ) , v ) ) // Use the count as the key to get max by. . max_by_key ( | ( count , _ ) | * count ) // Map the (count, vec) tuple back to the vec. // The count has served its purpose. . map ( | ( _ , v ) | v ) // In case the option was none (the input Vec was empty), return empty vec. . unwrap_or_else ( | | vec ! [ Region Unknown ] ) }
Best-guess a region string from one of the three known formats.
Best - guess a region string from one of the three known formats .
region_str
T