codes-iso-3166 0.1.5

This package contains an implementation of the ISO 3166 Country Codes specification.
Documentation
/*!
Provides lookup functions for [CountryCode] by secondary identifiers.
*/

use crate::part_1::CountryCode;

// ------------------------------------------------------------------------------------------------
// Public Macros
// ------------------------------------------------------------------------------------------------

// ------------------------------------------------------------------------------------------------
// Public Types
// ------------------------------------------------------------------------------------------------

// ------------------------------------------------------------------------------------------------
// Public Functions
// ------------------------------------------------------------------------------------------------

///
/// Lookup a [CountryCode] by it's three-letter code.
///
#[cfg(feature = "alpha_3_code")]
pub fn find_by_alpha_3_code(code: &str) -> Option<CountryCode> {
    // TODO: use lazy_static and HashMaps for actual indices!
    if code.len() == 3 && code.chars().all(|c| c.is_ascii_alphanumeric()) {
        crate::part_1::ALL_CODES
            .iter()
            .find(|c| c.alpha_3_code().map(|c| c == code).unwrap_or_default())
            .cloned()
    } else {
        None
    }
}

///
/// Lookup a [CountryCode] by it's numeric code.
///
#[cfg(feature = "numeric_code")]
pub fn find_by_numeric_code(code: u16) -> Option<CountryCode> {
    // TODO: use lazy_static and HashMaps for actual indices!
    crate::part_1::ALL_CODES
        .iter()
        .find(|c| c.numeric_code().map(|c| c == code).unwrap_or_default())
        .cloned()
}

// ------------------------------------------------------------------------------------------------
// Private Types
// ------------------------------------------------------------------------------------------------

// ------------------------------------------------------------------------------------------------
// Implementations
// ------------------------------------------------------------------------------------------------

// ------------------------------------------------------------------------------------------------
// Private Functions
// ------------------------------------------------------------------------------------------------

// ------------------------------------------------------------------------------------------------
// Modules
// ------------------------------------------------------------------------------------------------