fn compare_locale<S: Into<String> + std::fmt::Display>(cmp: &str, locales: &[S]) -> LocaleMatch {
    let mut outcome = LocaleMatch::None;
    // Split into language and region (e.g. `en-US`) if possible
    let cmp_parts: Vec<&str> = cmp.split('-').collect();

    for locale in locales {
        let locale = locale.to_string();
        // Split into language and region (e.g. `en-US`) if possible
        let parts: Vec<&str> = locale.split('-').collect();
        if locale == cmp {
            outcome = LocaleMatch::Exact(locale.to_string());
            // Any exact match voids anything after it (it'll be further down the list or
            // only a partial match from here on)
            break;
        } else if cmp_parts.first() == parts.first() {
            // If we've already had a partial match higher up the chain, this is void
            // But we shouldn't break in case there's an exact match coming up
            if !matches!(outcome, LocaleMatch::Language(_)) {
                outcome = LocaleMatch::Language(locale.to_string())
            }
        }
        // If there's no match, just continue on for now
    }

    outcome
}
Compares the given locale with the given vector of locales, identifying the
closest match. This handles possible case discrepancies automatically (e.g.
Safari before iOS 10.2 returned all locales in lower-case).

Exact matches with any supported locale are preferred to language-only (and
not region) matches. Remember that this function only matches a single
locale, not the list of the preferred locales (in which the first of either
kind of match is used as per [RFC 4647](https://www.rfc-editor.org/rfc/rfc4647.txt)).

This does NOT comply fully with [RFC 4647](https://www.rfc-editor.org/rfc/rfc4647.txt) yet, as only `xx-XX` form locales are
currently supported. This functionality will eventually be broken out into a
separate module for ease of use.
packages/perseus/src/i18n/locale_detector.rs