1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// This file is part of ICU4X. For terms of use, please see the file
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

//! This crate provides an experimental implementation of the `ECMA-402` traits using `ICU4X` library.

// https://github.com/unicode-org/icu4x/blob/main/docs/process/boilerplate.md#library-annotations
#![cfg_attr(
    not(test),
    deny(
        clippy::indexing_slicing,
        clippy::unwrap_used,
        clippy::expect_used,
        clippy::panic,
        clippy::exhaustive_structs,
        clippy::exhaustive_enums,
        missing_debug_implementations,
    )
)]

#[cfg(test)]
pub mod testing;

/// Implements ECMA-402 [`Intl.PluralRules`][link].
///
/// [link]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules
pub mod pluralrules;

/// Implements ECMA-402 [`Intl.ListFormat`][link].
///
/// [link]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat
pub mod list;

/// An adapter between [`DataLocale`] and [`ecma402_traits::Locale`].
#[derive(Debug, Hash, Clone, PartialEq)]
pub struct DataLocale(icu_provider::DataLocale);

impl DataLocale {
    /// Creates a `DataLocale` from any other [`ecma402_traits::Locale`]
    fn from_ecma_locale<L: ecma402_traits::Locale>(other: L) -> Self {
        #[allow(clippy::unwrap_used)] // ecma402_traits::Locale::to_string is a valid locale
        Self(
            other
                .to_string()
                .parse::<icu::locid::Locale>()
                .unwrap()
                .into(),
        )
    }
}

impl core::ops::Deref for DataLocale {
    type Target = icu_provider::DataLocale;
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

impl ecma402_traits::Locale for crate::DataLocale {}

impl std::fmt::Display for crate::DataLocale {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        self.0.fmt(f)
    }
}