fn from_tosec_region<S: AsRef<str> + ?Sized>(region_str: &S) -> Result<(Vec<&str>, Vec<Region>)> {
    let mut region_strings = Vec::new();
    let mut regions: IndexSet<Region> = IndexSet::new();
    let mut region_count = 0;
    let mut region_string_index = 0;

    for region_code in region_str.as_ref().split('-')
    {
        let region = TOSEC_REGION.get(region_code);
        if region_code.len() != 2 {
            return Err(RegionError::BadRegionCode(RegionFormat::TOSEC,
                                                  region_count,
                                                  region_string_index))
        }
        if let Some(region) = region {
            regions.insert(*region);
            region_strings.push(region_code);
            region_count += 1;
            region_string_index += region_code.len();
            region_string_index += "-".len();
        } else {
            return Err(RegionError::BadRegionCode(RegionFormat::TOSEC,
                                                  region_count,
                                                  region_string_index))
        }
    }

    if regions.is_empty() {
         Err(RegionError::NoRegions(RegionFormat::TOSEC))
    } else {
        Ok((region_strings, regions.into_iter().collect::<Vec<Region>>()))
    }
}
/// Parse a valid TOSEC region string into a `Vec<Region>`.
/// A valid region string is 2 uppercase letter country codes, separated by hyphens.
///
/// # Arguments
/// - `region_str` The region string.
Parse a valid TOSEC region string into a `Vec`.
A valid region string is 2 uppercase letter country codes, separated by hyphens.
Parse a valid TOSEC region string into a ` Vec ` . A valid region string is 2 uppercase letter country codes separated by hyphens .
fn from_tosec_region<S: AsRef<str> + ?Sized>(region_str: &S) -> Result<(Vec<&str>, Vec<Region>)> {
    let mut region_strings = Vec::new();
    let mut regions: IndexSet<Region> = IndexSet::new();
    let mut region_count = 0;
    let mut region_string_index = 0;
    for region_code in region_str.as_ref().split('-')
    {
        let region = TOSEC_REGION.get(region_code);
        if region_code.len() != 2 {
            return Err(RegionError::BadRegionCode(RegionFormat::TOSEC,
                                                  region_count,
                                                  region_string_index))
        }
        if let Some(region) = region {
            regions.insert(*region);
            region_strings.push(region_code);
            region_count += 1;
            region_string_index += region_code.len();
            region_string_index += "-".len();
        } else {
            return Err(RegionError::BadRegionCode(RegionFormat::TOSEC,
                                                  region_count,
                                                  region_string_index))
        }
    }
    if regions.is_empty() {
         Err(RegionError::NoRegions(RegionFormat::TOSEC))
    } else {
        Ok((region_strings, regions.into_iter().collect::<Vec<Region>>()))
    }
}
fn from_tosec_region < S : AsRef < str > + ? Sized > ( region_str : & S ) -> Result < ( Vec < & str > , Vec < Region > ) > { let mut region_strings = Vec :: new ( ) ; let mut regions : IndexSet < Region > = IndexSet :: new ( ) ; let mut region_count = 0 ; let mut region_string_index = 0 ; for region_code in region_str . as_ref ( ) . split ( '-' ) { let region = TOSEC_REGION . get ( region_code ) ; if region_code . len ( ) != 2 { return Err ( RegionError :: BadRegionCode ( RegionFormat :: TOSEC , region_count , region_string_index ) ) } if let Some ( region ) = region { regions . insert ( * region ) ; region_strings . push ( region_code ) ; region_count += 1 ; region_string_index += region_code . len ( ) ; region_string_index += " " . len ( ) ; } else { return Err ( RegionError :: BadRegionCode ( RegionFormat :: TOSEC , region_count , region_string_index ) ) } } if regions . is_empty ( ) { Err ( RegionError :: NoRegions ( RegionFormat :: TOSEC ) ) } else { Ok ( ( region_strings , regions . into_iter ( ) . collect :: < Vec < Region > > ( ) ) ) } }
Parse a valid TOSEC region string into a `Vec<Region>`.
Parse a valid TOSEC region string into a ` Vec<Region > ` .
region_str
&S
The region string.
The region string .