Debian Codegraph @

src/lib.rs

raw symbols SCIP
1 //! Global locale instances and system inspection.
2 //!
3 //! This is an auxiliary crate for i18n solutions that:
4 //!
5 //! - Holds the appropriate default instances of locale.
6 //! - Inspects the system for the initial values.
7 //!
8 //! You don't want to use it directly, but instead use an internationalisation crate like [locale].
9 //!
10 //! This crate is separate and intentionally minimal so that multiple i18n crates or multiple
11 //! versions of one that get into the application still share the current locale setting.
12 //!
13 //! [locale]: https://crates.io/crates/locale
14
15 #[macro_use]
16 extern crate lazy_staticrust-analyzer cargo locale_config 0.3.0 lazy_static/;
17
18 extern crate regexrust-analyzer cargo locale_config 0.3.0 regex/;
19
20 #[cfg(target_os = "macos")]
21 #[macro_use]
22 extern crate objc;
23
24 use regexrust-analyzer cargo regex 1.13.1 crate/::Regexrust-analyzer cargo regex 1.13.1 regex/string/Regex#;
25 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::{Borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#,Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#};
26 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/::RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#;
27 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::convertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/::AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#;
28 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/;
29 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::Mutexrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/Mutex#;
30
31 // ------------------------------ LANGUAGE RANGE ---------------------------------
32
33 /// Language and culture identifier.
34 ///
35 /// This object holds a [RFC4647] extended language range.
36 ///
37 /// The internal data may be owned or shared from object with lifetime `'a`. The lifetime can be
38 /// extended using the `into_static()` method, which internally clones the data as needed.
39 ///
40 /// # Syntax
41 ///
42 /// The range is composed of `-`-separated alphanumeric subtags, possibly replaced by `*`s. It
43 /// might be empty.
44 ///
45 /// In agreement with [RFC4647], this object only requires that the tag matches:
46 ///
47 /// ```ebnf
48 /// language_tag = (alpha{1,8} | "*")
49 /// ("-" (alphanum{1,8} | "*"))*
50 /// ```
51 ///
52 /// The exact interpretation is up to the downstream localization provider, but it expected that
53 /// it will be matched against a normalized [RFC5646] language tag, which has the structure:
54 ///
55 /// ```ebnf
56 /// language_tag = language
57 /// ("-" script)?
58 /// ("-" region)?
59 /// ("-" variant)*
60 /// ("-" extension)*
61 /// ("-" private)?
62 ///
63 /// language = alpha{2,3} ("-" alpha{3}){0,3}
64 ///
65 /// script = aplha{4}
66 ///
67 /// region = alpha{2}
68 /// | digit{3}
69 ///
70 /// variant = alphanum{5,8}
71 /// | digit alphanum{3}
72 ///
73 /// extension = [0-9a-wyz] ("-" alphanum{2,8})+
74 ///
75 /// private = "x" ("-" alphanum{1,8})+
76 /// ```
77 ///
78 /// * `language` is an [ISO639] 2-letter or, where not defined, 3-letter code. A code for
79 /// macro-language might be followed by code of specific dialect.
80 /// * `script` is an [ISO15924] 4-letter code.
81 /// * `region` is either an [ISO3166] 2-letter code or, for areas other than countries, [UN M.49]
82 /// 3-digit numeric code.
83 /// * `variant` is a string indicating variant of the language.
84 /// * `extension` and `private` define additional options. The private part has same structure as
85 /// the Unicode [`-u-` extension][u_ext]. Available options are documented for the facets that
86 /// use them.
87 ///
88 /// The values obtained by inspecting the system are normalized according to those rules.
89 ///
90 /// The content will be case-normalized as recommended in [RFC5646] Β§2.1.1, namely:
91 ///
92 /// * `language` is written in lowercase,
93 /// * `script` is written with first capital,
94 /// * `country` is written in uppercase and
95 /// * all other subtags are written in lowercase.
96 ///
97 /// When detecting system configuration, additional options that may be generated under the
98 /// [`-u-` extension][u_ext] currently are:
99 ///
100 /// * `cf` β€” Currency format (`account` for parenthesized negative values, `standard` for minus
101 /// sign).
102 /// * `fw` β€” First day of week (`mon` to `sun`).
103 /// * `hc` β€” Hour cycle (`h12` for 1–12, `h23` for 0–23).
104 /// * `ms` β€” Measurement system (`metric` or `ussystem`).
105 /// * `nu` β€” Numbering systemβ€”only decimal systems are currently used.
106 /// * `va` β€” Variant when locale is specified in Unix format and the tag after `@` does not
107 /// correspond to any variant defined in [Language subtag registry].
108 ///
109 /// And under the `-x-` extension, following options are defined:
110 ///
111 /// * `df` β€” Date format:
112 ///
113 /// * `iso`: Short date should be in ISO format of `yyyy-MM-dd`.
114 ///
115 /// For example `-df-iso`.
116 ///
117 /// * `dm` β€” Decimal separator for monetary:
118 ///
119 /// Followed by one or more Unicode codepoints in hexadecimal. For example `-dm-002d` means to
120 /// use comma.
121 ///
122 /// * `ds` β€” Decimal separator for numbers:
123 ///
124 /// Followed by one or more Unicode codepoints in hexadecimal. For example `-ds-002d` means to
125 /// use comma.
126 ///
127 /// * `gm` β€” Group (thousand) separator for monetary:
128 ///
129 /// Followed by one or more Unicode codepoints in hexadecimal. For example `-dm-00a0` means to
130 /// use non-breaking space.
131 ///
132 /// * `gs` β€” Group (thousand) separator for numbers:
133 ///
134 /// Followed by one or more Unicode codepoints in hexadecimal. For example `-ds-00a0` means to
135 /// use non-breaking space.
136 ///
137 /// * `ls` β€” List separator:
138 ///
139 /// Followed by one or more Unicode codepoints in hexadecimal. For example, `-ds-003b` means to
140 /// use a semicolon.
141 ///
142 /// [RFC5646]: https://www.rfc-editor.org/rfc/rfc5646.txt
143 /// [RFC4647]: https://www.rfc-editor.org/rfc/rfc4647.txt
144 /// [ISO639]: https://en.wikipedia.org/wiki/ISO_639
145 /// [ISO15924]: https://en.wikipedia.org/wiki/ISO_15924
146 /// [ISO3166]: https://en.wikipedia.org/wiki/ISO_3166
147 /// [UN M.49]: https://en.wikipedia.org/wiki/UN_M.49
148 /// [u_ext]: http://www.unicode.org/reports/tr35/#u_Extension
149 /// [Language subtag registry]: https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry
150 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:,Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:,Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:,Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:,PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
151 pub struct LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#<'a> {
152 languagerust-analyzer cargo locale_config 0.3.0 LanguageRange#language.: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, str>
153 }
154
155 lazy_staticrust-analyzer cargo lazy_static 1.5.0 lazy_static!! {
156 static ref REGULAR_LANGUAGE_RANGE_REGEXrust-analyzer cargo locale_config 0.3.0 REGULAR_LANGUAGE_RANGE_REGEX#: Regexrust-analyzer cargo regex 1.13.1 regex/string/Regex# = Regexrust-analyzer cargo regex 1.13.1 regex/string/Regex#::newrust-analyzer cargo regex 1.13.1 regex/string/impl#[Regex]new().(r"(?x) ^
157 (?P<language> (?:
158 [[:alpha:]]{2,3} (?: - [[:alpha:]]{3} ){0,3}
159 | \* ))
160 (?P<script> - (?: [[:alpha:]]{4} | \* ))?
161 (?P<region> - (?: [[:alpha:]]{2} | [[:digit:]]{3} | \* ))?
162 (?P<rest> (?: - (?: [[:alnum:]]{1,8} | \* ))*)
163 $ ").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
164 static ref LANGUAGE_RANGE_REGEXrust-analyzer cargo locale_config 0.3.0 LANGUAGE_RANGE_REGEX#: Regexrust-analyzer cargo regex 1.13.1 regex/string/Regex# = Regexrust-analyzer cargo regex 1.13.1 regex/string/Regex#::newrust-analyzer cargo regex 1.13.1 regex/string/impl#[Regex]new().(r"(?x) ^
165 (?: [[:alpha:]]{1,8} | \* )
166 (?: - (?: [[:alnum:]]{1,8} | \* ))*
167 $ ").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
168 static ref UNIX_INVARIANT_REGEXrust-analyzer cargo locale_config 0.3.0 UNIX_INVARIANT_REGEX#: Regexrust-analyzer cargo regex 1.13.1 regex/string/Regex# = Regexrust-analyzer cargo regex 1.13.1 regex/string/Regex#::newrust-analyzer cargo regex 1.13.1 regex/string/impl#[Regex]new().(r"(?ix) ^
169 (?: c | posix )
170 (?: \. (?: [0-9a-zA-Z-]{1,20} ))?
171 $ ").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
172 static ref UNIX_TAG_REGEXrust-analyzer cargo locale_config 0.3.0 UNIX_TAG_REGEX#: Regexrust-analyzer cargo regex 1.13.1 regex/string/Regex# = Regexrust-analyzer cargo regex 1.13.1 regex/string/Regex#::newrust-analyzer cargo regex 1.13.1 regex/string/impl#[Regex]new().(r"(?ix) ^
173 (?P<language> [[:alpha:]]{2,3} )
174 (?: _ (?P<region> [[:alpha:]]{2} | [[:digit:]]{3} ))?
175 (?: \. (?P<encoding> [0-9a-zA-Z-]{1,20} ))?
176 (?: @ (?P<variant> [[:alnum:]]{1,20} ))?
177 $ ").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
178 }
179
180 fn is_ownedrust-analyzer cargo locale_config 0.3.0 is_owned().<'a, T: ToOwnedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/ToOwned# + ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(c: &Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, T>) -> bool {
181 match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().c {
182 Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(_) => true,
183 Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(_) => false,
184 }
185 }
186
187 fn canon_lowerrust-analyzer cargo locale_config 0.3.0 canon_lower().<'a>(o: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a str>) -> Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, str> {
188 match o {
189 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(""),
190 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(s) =>
191 if s.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(char::is_uppercaserust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]is_uppercase().) {
192 Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(s.to_ascii_lowercaserust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]to_ascii_lowercase().())
193 } else {
194 Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(s)
195 },
196 }
197 }
198
199 fn canon_scriptrust-analyzer cargo locale_config 0.3.0 canon_script().<'a>(o: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a str>) -> Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, str> {
200 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(o.map_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map_or().(true, |s| s.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() >= 2 && &s[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0..1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). == "-"));
201 match o {
202 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(""),
203 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(s) =>
204 if s[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#2]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Chars<'a>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().is_uppercaserust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]is_uppercase().() &&
205 s[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().2..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().().allrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#all().(char::is_lowercaserust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]is_lowercase().) {
206 Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(s)
207 } else {
208 Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`From<&str>`]from().("-") rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().+rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().
209 s[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#2]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..to_ascii_uppercaserust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]to_ascii_uppercase().().as_refrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`AsRef<str>`]as_ref().() rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().+rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().
210 s[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().2..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..to_ascii_lowercaserust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]to_ascii_lowercase().().as_refrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`AsRef<str>`]as_ref().())
211 },
212 }
213 }
214
215 fn canon_upperrust-analyzer cargo locale_config 0.3.0 canon_upper().<'a>(o: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a str>) -> Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, str> {
216 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(o.map_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map_or().(true, |s| s.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). 1 && &s[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0..1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). == "-"));
217 match o {
218 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(""),
219 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(s) =>
220 if s.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(char::is_lowercaserust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]is_lowercase().) {
221 Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(s.to_ascii_uppercaserust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]to_ascii_uppercase().())
222 } else {
223 Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(s)
224 },
225 }
226 }
227
228 impl<'a> LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#<'a> {
229 /// Construct LanguageRange from string, with normalization.
230 ///
231 /// LanguageRange must follow the [RFC4647] syntax.
232 /// It will be case-normalized as recommended in [RFC5646] Β§2.1.1, namely:
233 ///
234 /// * `language`, if recognized, is written in lowercase,
235 /// * `script`, if recognized, is written with first capital,
236 /// * `country`, if recognized, is written in uppercase and
237 /// * all other subtags are written in lowercase.
238 ///
239 /// [RFC5646]: https://www.rfc-editor.org/rfc/rfc5646.txt
240 /// [RFC4647]: https://www.rfc-editor.org/rfc/rfc4647.txt
241 pub fn newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().(lt: &'a str) -> Resultrust-analyzer cargo locale_config 0.3.0 Result#<LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#> {
242 if lt rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."" {
243 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange# {
244 languagerust-analyzer cargo locale_config 0.3.0 LanguageRange#language.: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(lt),
245 });
246 } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(caps) = REGULAR_LANGUAGE_RANGE_REGEXrust-analyzer cargo locale_config 0.3.0 REGULAR_LANGUAGE_RANGE_REGEX..capturesrust-analyzer cargo regex 1.13.1 regex/string/impl#[Regex]captures().(lt) {
247 let language = canon_lowerrust-analyzer cargo locale_config 0.3.0 canon_lower().(caps.namerust-analyzer cargo regex 1.13.1 regex/string/impl#[`Captures<'h>`]name().("language").maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|m| m.as_strrust-analyzer cargo regex 1.13.1 regex/string/impl#[`Match<'h>`]as_str().()));
248 let script = canon_scriptrust-analyzer cargo locale_config 0.3.0 canon_script().(caps.namerust-analyzer cargo regex 1.13.1 regex/string/impl#[`Captures<'h>`]name().("script").maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|m| m.as_strrust-analyzer cargo regex 1.13.1 regex/string/impl#[`Match<'h>`]as_str().()));
249 let region = canon_upperrust-analyzer cargo locale_config 0.3.0 canon_upper().(caps.namerust-analyzer cargo regex 1.13.1 regex/string/impl#[`Captures<'h>`]name().("region").maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|m| m.as_strrust-analyzer cargo regex 1.13.1 regex/string/impl#[`Match<'h>`]as_str().()));
250 let rest = canon_lowerrust-analyzer cargo locale_config 0.3.0 canon_lower().(caps.namerust-analyzer cargo regex 1.13.1 regex/string/impl#[`Captures<'h>`]name().("rest").maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|m| m.as_strrust-analyzer cargo regex 1.13.1 regex/string/impl#[`Match<'h>`]as_str().()));
251 if is_ownedrust-analyzer cargo locale_config 0.3.0 is_owned().(&language) ||
252 is_ownedrust-analyzer cargo locale_config 0.3.0 is_owned().(&script) ||
253 is_ownedrust-analyzer cargo locale_config 0.3.0 is_owned().(&region) ||
254 is_ownedrust-analyzer cargo locale_config 0.3.0 is_owned().(&rest)
255 {
256 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange# {
257 languagerust-analyzer cargo locale_config 0.3.0 LanguageRange#language.: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(
258 language.into_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, B>`]into_owned().() rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().+rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().
259 script.borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'a, B>`][`Borrow<B>`]borrow().() rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().+rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().
260 region.borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'a, B>`][`Borrow<B>`]borrow().() rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().+rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().
261 rest.borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'a, B>`][`Borrow<B>`]borrow().()),
262 });
263 } else {
264 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange# {
265 languagerust-analyzer cargo locale_config 0.3.0 LanguageRange#language.: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(lt),
266 });
267 }
268 } else if LANGUAGE_RANGE_REGEXrust-analyzer cargo locale_config 0.3.0 LANGUAGE_RANGE_REGEX..is_matchrust-analyzer cargo regex 1.13.1 regex/string/impl#[Regex]is_match().(lt) {
269 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange# {
270 languagerust-analyzer cargo locale_config 0.3.0 LanguageRange#language.: canon_lowerrust-analyzer cargo locale_config 0.3.0 canon_lower().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(lt)),
271 });
272 } else {
273 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo locale_config 0.3.0 Error#::NotWellFormedrust-analyzer cargo locale_config 0.3.0 Error#NotWellFormed#);
274 }
275 }
276
277 /// Return LanguageRange for the invariant locale.
278 ///
279 /// Invariant language is identified simply by empty string.
280 pub fn invariantrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]invariant().() -> LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#<'static> {
281 LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange# { languagerust-analyzer cargo locale_config 0.3.0 LanguageRange#language.: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#("") }
282 }
283
284 /// Clone the internal data to extend lifetime.
285 pub fn into_staticrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]into_static().(self) -> LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#<'static> {
286 LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange# {
287 languagerust-analyzer cargo locale_config 0.3.0 LanguageRange#language.: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(self.languagerust-analyzer cargo locale_config 0.3.0 LanguageRange#language..into_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, B>`]into_owned().())
288 }
289 }
290
291 /// Create new instance sharing the internal data.
292 pub fn to_sharedrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]to_shared().(&'a self) -> Selfrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`] {
293 LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange# {
294 languagerust-analyzer cargo locale_config 0.3.0 LanguageRange#language.: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(self.languagerust-analyzer cargo locale_config 0.3.0 LanguageRange#language..borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'a, B>`][`Borrow<B>`]borrow().())
295 }
296 }
297
298 /// Create language tag from Unix/Linux/GNU locale tag.
299 ///
300 /// Unix locale tags have the form
301 ///
302 /// > *language* [ `_` *region* ] [ `.` *encoding* ] [ `@` *variant* ]
303 ///
304 /// The *language* and *region* have the same format as RFC5646. *Encoding* is not relevant
305 /// here, since Rust always uses Utf-8. That leaves *variant*, which is unfortunately rather
306 /// free-form. So this function will translate known variants to corresponding RFC5646 subtags
307 /// and represent anything else with Unicode POSIX variant (`-u-va-`) extension.
308 ///
309 /// Note: This function is public here for benefit of applications that may come across this
310 /// kind of tags from other sources than system configuration.
311 pub fn from_unixrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]from_unix().(s: &str) -> Resultrust-analyzer cargo locale_config 0.3.0 Result#<LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#<'static>> {
312 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(caps) = UNIX_TAG_REGEXrust-analyzer cargo locale_config 0.3.0 UNIX_TAG_REGEX..capturesrust-analyzer cargo regex 1.13.1 regex/string/impl#[Regex]captures().(s) {
313 let src_variant = caps.namerust-analyzer cargo regex 1.13.1 regex/string/impl#[`Captures<'h>`]name().("variant").maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|m| m.as_strrust-analyzer cargo regex 1.13.1 regex/string/impl#[`Match<'h>`]as_str().()).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().("").to_ascii_lowercaserust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]to_ascii_lowercase().();
314 let mut res = caps.namerust-analyzer cargo regex 1.13.1 regex/string/impl#[`Captures<'h>`]name().("language").maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|m| m.as_strrust-analyzer cargo regex 1.13.1 regex/string/impl#[`Match<'h>`]as_str().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().to_ascii_lowercaserust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]to_ascii_lowercase().();
315 let region = caps.namerust-analyzer cargo regex 1.13.1 regex/string/impl#[`Captures<'h>`]name().("region").maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|m| m.as_strrust-analyzer cargo regex 1.13.1 regex/string/impl#[`Match<'h>`]as_str().()).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().("");
316 let mut script = "";
317 let mut variant = "";
318 let mut uvariant = "";
319 match src_variant.as_refrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`AsRef<str>`]as_ref().() {
320 // Variants seen in the wild in GNU LibC (via http://lh.2xlibre.net/) or in Debian
321 // GNU/Linux Stretch system. Treatment of things not found in RFC5646 subtag registry
322 // (http://www.iana.org/assignments/language-subtag-registry/language-subtag-registry)
323 // or CLDR according to notes at https://wiki.openoffice.org/wiki/LocaleMapping.
324 // Dialects:
325 // aa_ER@saaho - NOTE: Can't be found under that name in RFC5646 subtag registry,
326 // but there is language Saho with code ssy, which is likely that thing.
327 "saaho" if res rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq()."aa" => res = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`From<&str>`]from().("ssy"),
328 // Scripts:
329 // @arabic
330 "arabic" => script = "Arab",
331 // @cyrillic
332 "cyrl" => script = "Cyrl",
333 "cyrillic" => script = "Cyrl",
334 // @devanagari
335 "devanagari" => script = "Deva",
336 // @hebrew
337 "hebrew" => script = "Hebr",
338 // tt@iqtelif
339 // Neither RFC5646 subtag registry nor CLDR knows anything about this, but as best
340 // as I can tell it is Tatar name for Latin (default is Cyrillic).
341 "iqtelif" => script = "Latn",
342 // @Latn
343 "latn" => script = "Latn",
344 // @latin
345 "latin" => script = "Latn",
346 // en@shaw
347 "shaw" => script = "Shaw",
348 // Variants:
349 // sr@ijekavianlatin
350 "ijekavianlatin" => {
351 script = "Latn";
352 variant = "ijekavsk";
353 },
354 // sr@ije
355 "ije" => variant = "ijekavsk",
356 // sr@ijekavian
357 "ijekavian" => variant = "ijekavsk",
358 // ca@valencia
359 "valencia" => variant = "valencia",
360 // Currencies:
361 // @euro - NOTE: We follow suite of Java and Openoffice and ignore it, because it
362 // is default for all locales where it sometimes appears now, and because we use
363 // explicit currency in monetary formatting anyway.
364 "euro" => {},
365 // Collation:
366 // gez@abegede - NOTE: This is collation, but CLDR does not have any code for it,
367 // so we for the moment leave it fall through as -u-va- instead of -u-co-.
368 // Anything else:
369 // en@boldquot, en@quot, en@piglatin - just randomish stuff
370 // @cjknarrow - beware, it's gonna end up as -u-va-cjknarro due to lenght limit
371 s if s.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().8 => uvariant = &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().s,
372 s => uvariant = &s[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#8]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., // the subtags are limited to 8 chars, but some are longer
373 };
374 if script rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne()."" {
375 res.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('-');
376 res.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(script);
377 }
378 if region rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne()."" {
379 res.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('-');
380 res.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(&*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Deref]deref().region.to_ascii_uppercaserust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]to_ascii_uppercase().());
381 }
382 if variant rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne()."" {
383 res.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('-');
384 res.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(variant);
385 }
386 if uvariant rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne()."" {
387 res.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().("-u-va-");
388 res.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(uvariant);
389 }
390 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange# {
391 languagerust-analyzer cargo locale_config 0.3.0 LanguageRange#language.: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(res)
392 });
393 } else if UNIX_INVARIANT_REGEXrust-analyzer cargo locale_config 0.3.0 UNIX_INVARIANT_REGEX..is_matchrust-analyzer cargo regex 1.13.1 regex/string/impl#[Regex]is_match().(s) {
394 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::invariantrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]invariant().())
395 } else {
396 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo locale_config 0.3.0 Error#::NotWellFormedrust-analyzer cargo locale_config 0.3.0 Error#NotWellFormed#);
397 }
398 }
399 }
400
401 impl<'a> AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<str> for LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#<'a> {
402 fn as_refrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`][`AsRef<str>`]as_ref().(&self) -> &str {
403 self.languagerust-analyzer cargo locale_config 0.3.0 LanguageRange#language..as_refrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, T>`][`AsRef<T>`]as_ref().()
404 }
405 }
406
407 impl<'a> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#<'a> {
408 fn fmtrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
409 self.languagerust-analyzer cargo locale_config 0.3.0 LanguageRange#language..fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, B>`][Display]fmt().(f)
410 }
411 }
412
413 // -------------------------------- LOCALE -------------------------------------
414
415 /// Locale configuration.
416 ///
417 /// Users may accept several languages in some order of preference and may want to use rules from
418 /// different culture for some particular aspect of the program behaviour, and operating systems
419 /// allow them to specify this (to various extent).
420 ///
421 /// The `Locale` objects represent the user configuration. They contain:
422 ///
423 /// - The primary `LanguageRange`.
424 /// - Optional category-specific overrides.
425 /// - Optional fallbacks in case data (usually translations) for the primary language are not
426 /// available.
427 ///
428 /// The set of categories is open-ended. The `locale` crate uses five well-known categories
429 /// `messages`, `numeric`, `time`, `collate` and `monetary`, but some systems define additional
430 /// ones (GNU Linux has additionally `paper`, `name`, `address`, `telephone` and `measurement`) and
431 /// these are provided in the user default `Locale` and other libraries can use them.
432 ///
433 /// `Locale` is represented by a `,`-separated sequence of tags in `LanguageRange` syntax, where
434 /// all except the first one may be preceded by category name and `=` sign.
435 ///
436 /// The first tag indicates the default locale, the tags prefixed by category names indicate
437 /// _overrides_ for those categories and the remaining tags indicate fallbacks.
438 ///
439 /// Note that a syntactically valid value of HTTP `Accept-Language` header is a valid `Locale`. Not
440 /// the other way around though due to the presence of category selectors.
441 // TODO: Interning
442 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:,Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:,Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:,Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:,PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
443 pub struct Localerust-analyzer cargo locale_config 0.3.0 Locale# {
444 // TODO: Intern the string for performance reasons
445 // XXX: Store pre-split to LanguageTags?
446 innerrust-analyzer cargo locale_config 0.3.0 Locale#inner.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
447 }
448
449 lazy_staticrust-analyzer cargo lazy_static 1.5.0 lazy_static!! {
450 static ref LOCALE_ELEMENT_REGEXrust-analyzer cargo locale_config 0.3.0 LOCALE_ELEMENT_REGEX#: Regexrust-analyzer cargo regex 1.13.1 regex/string/Regex# = Regexrust-analyzer cargo regex 1.13.1 regex/string/Regex#::newrust-analyzer cargo regex 1.13.1 regex/string/impl#[Regex]new().(r"(?ix) ^
451 (?: (?P<category> [[:alpha:]]{1,20} ) = )?
452 (?P<tag> (?: [[:alnum:]] | - | \* )+ )
453 $ ").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
454 }
455
456 impl Localerust-analyzer cargo locale_config 0.3.0 Locale# {
457 /// Obtain the user default locale.
458 ///
459 /// This is the locale indicated by operating environment.
460 pub fn user_defaultrust-analyzer cargo locale_config 0.3.0 impl#[Locale]user_default().() -> Localerust-analyzer cargo locale_config 0.3.0 Locale# {
461 USER_LOCALErust-analyzer cargo locale_config 0.3.0 USER_LOCALE..clonerust-analyzer cargo locale_config 0.3.0 impl#[Locale][Clone]clone().()
462 }
463
464 /// Obtain the global default locale.
465 ///
466 /// The global default for `current()` locale. Defaults to `user_default()`.
467 pub fn global_defaultrust-analyzer cargo locale_config 0.3.0 impl#[Locale]global_default().() -> Localerust-analyzer cargo locale_config 0.3.0 Locale# {
468 GLOBAL_LOCALErust-analyzer cargo locale_config 0.3.0 GLOBAL_LOCALE..lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]lock().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().clonerust-analyzer cargo locale_config 0.3.0 impl#[Locale][Clone]clone().()
469 }
470
471 /// Change the global default locale.
472 ///
473 /// Setting this overrides the default for new threads and threads that didn't do any
474 /// locale-aware operation yet.
475 pub fn set_global_defaultrust-analyzer cargo locale_config 0.3.0 impl#[Locale]set_global_default().(lb: Localerust-analyzer cargo locale_config 0.3.0 Locale#) {
476 *rust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`MutexGuard<'_, T>`][DerefMut]deref_mut().GLOBAL_LOCALErust-analyzer cargo locale_config 0.3.0 GLOBAL_LOCALE..lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]lock().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() = lb;
477 }
478
479 /// Obtain the current locale of current thread.
480 ///
481 /// Defaults to `global_default()` on first use in each thread.
482 pub fn currentrust-analyzer cargo locale_config 0.3.0 impl#[Locale]current().() -> Localerust-analyzer cargo locale_config 0.3.0 Locale# {
483 CURRENT_LOCALErust-analyzer cargo locale_config 0.3.0 CURRENT_LOCALE..withrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/local/impl#[`LocalKey<T>`]with().(|l| l.borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow().().clonerust-analyzer cargo locale_config 0.3.0 impl#[Locale][Clone]clone().())
484 }
485
486 /// Change the current locale of current thread.
487 pub fn set_currentrust-analyzer cargo locale_config 0.3.0 impl#[Locale]set_current().(lb: Localerust-analyzer cargo locale_config 0.3.0 Locale#) {
488 CURRENT_LOCALErust-analyzer cargo locale_config 0.3.0 CURRENT_LOCALE..withrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/local/impl#[`LocalKey<T>`]with().(|l| *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefMut<'_, T>`][DerefMut]deref_mut().l.borrow_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow_mut().() = lb);
489 }
490
491 /// Construct locale from the string representation.
492 ///
493 /// `Locale` is represented by a `,`-separated sequence of tags in `LanguageRange` syntax, where
494 /// all except the first one may be preceded by category name and `=` sign.
495 ///
496 /// The first tag indicates the default locale, the tags prefixed by category names indicate
497 /// _overrides_ for those categories and the remaining tags indicate fallbacks.
498 pub fn newrust-analyzer cargo locale_config 0.3.0 impl#[Locale]new().(s: &str) -> Resultrust-analyzer cargo locale_config 0.3.0 Result#<Localerust-analyzer cargo locale_config 0.3.0 Locale#> {
499 let mut i = s.splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().(',');
500 let mut res = Localerust-analyzer cargo locale_config 0.3.0 Locale#::fromrust-analyzer cargo locale_config 0.3.0 impl#[Locale][`From<LanguageRange<'a>>`]from().(
501 tryrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/`r#try`!!(LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().(
502 i.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Split<'a, P>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()))); // NOTE: split "" is (""), not ()
503 for t in i {
504 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(caps) = LOCALE_ELEMENT_REGEXrust-analyzer cargo locale_config 0.3.0 LOCALE_ELEMENT_REGEX..capturesrust-analyzer cargo regex 1.13.1 regex/string/impl#[Regex]captures().(t) {
505 let tag = tryrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/`r#try`!!(LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().(
506 tryrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/`r#try`!!(caps.namerust-analyzer cargo regex 1.13.1 regex/string/impl#[`Captures<'h>`]name().("tag").maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|m| m.as_strrust-analyzer cargo regex 1.13.1 regex/string/impl#[`Match<'h>`]as_str().()).ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(Errorrust-analyzer cargo locale_config 0.3.0 Error#::NotWellFormedrust-analyzer cargo locale_config 0.3.0 Error#NotWellFormed#))));
507 match caps.namerust-analyzer cargo regex 1.13.1 regex/string/impl#[`Captures<'h>`]name().("category").maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|m| m.as_strrust-analyzer cargo regex 1.13.1 regex/string/impl#[`Match<'h>`]as_str().()) {
508 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(cat) => res.add_categoryrust-analyzer cargo locale_config 0.3.0 impl#[Locale]add_category().(cat.to_ascii_lowercaserust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]to_ascii_lowercase().().as_refrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`AsRef<str>`]as_ref().(), &tag),
509 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => res.addrust-analyzer cargo locale_config 0.3.0 impl#[Locale]add().(&tag),
510 }
511 } else {
512 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo locale_config 0.3.0 Error#::NotWellFormedrust-analyzer cargo locale_config 0.3.0 Error#NotWellFormed#);
513 }
514 }
515 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(res);
516 }
517
518 /// Construct invariant locale.
519 ///
520 /// Invariant locale is represented simply with empty string.
521 pub fn invariantrust-analyzer cargo locale_config 0.3.0 impl#[Locale]invariant().() -> Localerust-analyzer cargo locale_config 0.3.0 Locale# {
522 Localerust-analyzer cargo locale_config 0.3.0 Locale#::fromrust-analyzer cargo locale_config 0.3.0 impl#[Locale][`From<LanguageRange<'a>>`]from().(LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::invariantrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]invariant().())
523 }
524
525 /// Append fallback language tag.
526 ///
527 /// Adds fallback to the end of the list.
528 pub fn addrust-analyzer cargo locale_config 0.3.0 impl#[Locale]add().(&mut self, tag: &LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#) {
529 for i in self.innerrust-analyzer cargo locale_config 0.3.0 Locale#inner..splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().(',') {
530 if i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().tag.as_refrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`][`AsRef<str>`]as_ref().() {
531 return; // don't add duplicates
532 }
533 }
534 self.innerrust-analyzer cargo locale_config 0.3.0 Locale#inner..push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(",");
535 self.innerrust-analyzer cargo locale_config 0.3.0 Locale#inner..push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(tag.as_refrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`][`AsRef<str>`]as_ref().());
536 }
537
538 /// Append category override.
539 ///
540 /// Appending new override for a category that already has one will not replace the existing
541 /// override. This might change in future.
542 pub fn add_categoryrust-analyzer cargo locale_config 0.3.0 impl#[Locale]add_category().(&mut self, category: &str, tag: &LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#) {
543 if self.innerrust-analyzer cargo locale_config 0.3.0 Locale#inner..splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().(',').nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Split<'a, P>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().tag.as_refrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`][`AsRef<str>`]as_ref().() {
544 return; // don't add useless override equal to the primary tag
545 }
546 for i in self.innerrust-analyzer cargo locale_config 0.3.0 Locale#inner..splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().(',') {
547 if i.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().(category) &&
548 i[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().category.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().()..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("=") &&
549 &i[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().category.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().tag.as_refrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`][`AsRef<str>`]as_ref().() {
550 return; // don't add duplicates
551 }
552 }
553 self.innerrust-analyzer cargo locale_config 0.3.0 Locale#inner..push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(",");
554 self.innerrust-analyzer cargo locale_config 0.3.0 Locale#inner..push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(category);
555 self.innerrust-analyzer cargo locale_config 0.3.0 Locale#inner..push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().("=");
556 self.innerrust-analyzer cargo locale_config 0.3.0 Locale#inner..push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(tag.as_refrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`][`AsRef<str>`]as_ref().());
557 }
558
559 /// Iterate over `LanguageRange`s in this `Locale`.
560 ///
561 /// Returns tuples of optional category (as string) and corresponding `LanguageRange`. All tags
562 /// in the list are returned, in order of preference.
563 ///
564 /// The iterator is guaranteed to return at least one value.
565 pub fn tagsrust-analyzer cargo locale_config 0.3.0 impl#[Locale]tags().<'a>(&'a self) -> Tagsrust-analyzer cargo locale_config 0.3.0 Tags#<'a> {
566 Tagsrust-analyzer cargo locale_config 0.3.0 Tags# { tagsrust-analyzer cargo locale_config 0.3.0 Tags#tags.: self.innerrust-analyzer cargo locale_config 0.3.0 Locale#inner..splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().(","), }
567 }
568
569 /// Iterate over `LanguageRange`s in this `Locale` applicable to given category.
570 ///
571 /// Returns `LanguageRange`s in the `Locale` that are applicable to provided category. The tags
572 /// are returned in order of preference, which means the category-specific ones first and then
573 /// the generic ones.
574 ///
575 /// The iterator is guaranteed to return at least one value.
576 pub fn tags_forrust-analyzer cargo locale_config 0.3.0 impl#[Locale]tags_for().<'a, 'c>(&'a self, category: &'c str) -> TagsForrust-analyzer cargo locale_config 0.3.0 TagsFor#<'a, 'c> {
577 let mut tags = self.innerrust-analyzer cargo locale_config 0.3.0 Locale#inner..splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().(",");
578 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(s) = tags.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Split<'a, P>`][Clone]clone().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Split<'a, P>`][Iterator]next().() {
579 if s.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().(category) && s[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().category.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().()..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("=") {
580 return TagsForrust-analyzer cargo locale_config 0.3.0 TagsFor# {
581 srcrust-analyzer cargo locale_config 0.3.0 TagsFor#src.: self.innerrust-analyzer cargo locale_config 0.3.0 Locale#inner..as_refrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`AsRef<str>`]as_ref().(),
582 tagsrust-analyzer cargo locale_config 0.3.0 TagsFor#tags.: tags,
583 categoryrust-analyzer cargo locale_config 0.3.0 TagsFor#category.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(category),
584 };
585 }
586 tags.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Split<'a, P>`][Iterator]next().();
587 }
588 return TagsForrust-analyzer cargo locale_config 0.3.0 TagsFor# {
589 srcrust-analyzer cargo locale_config 0.3.0 TagsFor#src.: self.innerrust-analyzer cargo locale_config 0.3.0 Locale#inner..as_refrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`AsRef<str>`]as_ref().(),
590 tagsrust-analyzer cargo locale_config 0.3.0 TagsFor#tags.: self.innerrust-analyzer cargo locale_config 0.3.0 Locale#inner..splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().(","),
591 categoryrust-analyzer cargo locale_config 0.3.0 TagsFor#category.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
592 };
593 }
594 }
595
596 /// Locale is specified by a string tag. This is the way to access it.
597 // FIXME: Do we want to provide the full string representation? We would have it as single string
598 // then.
599 impl AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<str> for Localerust-analyzer cargo locale_config 0.3.0 Locale# {
600 fn as_refrust-analyzer cargo locale_config 0.3.0 impl#[Locale][`AsRef<str>`]as_ref().(&self) -> &str {
601 self.innerrust-analyzer cargo locale_config 0.3.0 Locale#inner..as_refrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`AsRef<str>`]as_ref().()
602 }
603 }
604
605 impl<'a> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#<'a>> for Localerust-analyzer cargo locale_config 0.3.0 Locale# {
606 fn fromrust-analyzer cargo locale_config 0.3.0 impl#[Locale][`From<LanguageRange<'a>>`]from().(t: LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#<'a>) -> Localerust-analyzer cargo locale_config 0.3.0 Locale# {
607 Localerust-analyzer cargo locale_config 0.3.0 Locale# {
608 innerrust-analyzer cargo locale_config 0.3.0 Locale#inner.: t.languagerust-analyzer cargo locale_config 0.3.0 LanguageRange#language..into_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, B>`]into_owned().(),
609 }
610 }
611 }
612
613 impl fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for Localerust-analyzer cargo locale_config 0.3.0 Locale# {
614 fn fmtrust-analyzer cargo locale_config 0.3.0 impl#[Locale][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
615 self.innerrust-analyzer cargo locale_config 0.3.0 Locale#inner..fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Display]fmt().(f)
616 }
617 }
618
619 /// Iterator over `LanguageRange`s for all categories in a `Locale`
620 ///
621 /// Returns tuples of optional category (as string) and corresponding `LanguageRange`. All tags
622 /// in the list are returned, in order of preference.
623 ///
624 /// The iterator is guaranteed to return at least one value.
625 pub struct Tagsrust-analyzer cargo locale_config 0.3.0 Tags#<'a> {
626 tagsrust-analyzer cargo locale_config 0.3.0 Tags#tags.: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::Splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/Split#<'a, &'static str>,
627 }
628
629 impl<'a> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for Tagsrust-analyzer cargo locale_config 0.3.0 Tags#<'a> {
630 type Itemrust-analyzer cargo locale_config 0.3.0 impl#[`Tags<'a>`][Iterator]Item# = (Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a str>, LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#<'a>);
631 fn nextrust-analyzer cargo locale_config 0.3.0 impl#[`Tags<'a>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo locale_config 0.3.0 impl#[`Tags<'a>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
632 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(s) = self.tagsrust-analyzer cargo locale_config 0.3.0 Tags#tags..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Split<'a, P>`][Iterator]next().() {
633 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(i) = s.findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().('=') {
634 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((
635 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&s[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().),
636 LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange# { languagerust-analyzer cargo locale_config 0.3.0 LanguageRange#language.: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(&s[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().), }));
637 } else {
638 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((
639 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
640 LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange# { languagerust-analyzer cargo locale_config 0.3.0 LanguageRange#language.: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(s), }));
641 }
642 } else {
643 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
644 }
645 }
646 }
647
648 /// Iterator over `LanguageRange`s for specific category in a `Locale`
649 ///
650 /// Returns `LanguageRange`s in the `Locale` that are applicable to provided category. The tags
651 /// are returned in order of preference, which means the category-specific ones first and then
652 /// the generic ones.
653 ///
654 /// The iterator is guaranteed to return at least one value.
655 pub struct TagsForrust-analyzer cargo locale_config 0.3.0 TagsFor#<'a, 'c> {
656 srcrust-analyzer cargo locale_config 0.3.0 TagsFor#src.: &'a str,
657 tagsrust-analyzer cargo locale_config 0.3.0 TagsFor#tags.: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::Splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/Split#<'a, &'static str>,
658 categoryrust-analyzer cargo locale_config 0.3.0 TagsFor#category.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'c str>,
659 }
660
661 impl<'a, 'c> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for TagsForrust-analyzer cargo locale_config 0.3.0 TagsFor#<'a, 'c> {
662 type Itemrust-analyzer cargo locale_config 0.3.0 impl#[`TagsFor<'a, 'c>`][Iterator]Item# = LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#<'a>;
663 fn nextrust-analyzer cargo locale_config 0.3.0 impl#[`TagsFor<'a, 'c>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo locale_config 0.3.0 impl#[`TagsFor<'a, 'c>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
664 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(cat) = self.categoryrust-analyzer cargo locale_config 0.3.0 TagsFor#category. {
665 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(s) = self.tagsrust-analyzer cargo locale_config 0.3.0 TagsFor#tags..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Split<'a, P>`][Iterator]next().() {
666 if s.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().(cat) && s[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().cat.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().()..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("=") {
667 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(
668 LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange# { languagerust-analyzer cargo locale_config 0.3.0 LanguageRange#language.: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(&s[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().cat.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().()+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().) });
669 }
670 }
671 self.categoryrust-analyzer cargo locale_config 0.3.0 TagsFor#category. = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
672 self.tagsrust-analyzer cargo locale_config 0.3.0 TagsFor#tags. = self.srcrust-analyzer cargo locale_config 0.3.0 TagsFor#src..splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().(",");
673 }
674 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(s) = self.tagsrust-analyzer cargo locale_config 0.3.0 TagsFor#tags..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Split<'a, P>`][Iterator]next().() {
675 if s.findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().('=').is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() {
676 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(
677 LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#{ languagerust-analyzer cargo locale_config 0.3.0 LanguageRange#language.: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(s) });
678 }
679 }
680 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
681 }
682 }
683
684 // ------------------------------- INSTANCES -----------------------------------
685
686 // TODO: We only need this until either std::sync::StaticMutex or std::sync::Mutex becomes usable
687 // with normal `static`.
688 // FIX-THE-TODO: Do we? A mutex might be usable, but we still need to initialize the value inside
689 // on first access!
690 lazy_staticrust-analyzer cargo lazy_static 1.5.0 lazy_static!! {
691 // TODO: Implement the constructor
692 static ref USER_LOCALErust-analyzer cargo locale_config 0.3.0 USER_LOCALE#: Localerust-analyzer cargo locale_config 0.3.0 Locale# = system_localerust-analyzer cargo locale_config 0.3.0 system_locale().();
693 static ref GLOBAL_LOCALErust-analyzer cargo locale_config 0.3.0 GLOBAL_LOCALE#: Mutexrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/Mutex#<Localerust-analyzer cargo locale_config 0.3.0 Locale#> = Mutexrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/Mutex#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]new().(Localerust-analyzer cargo locale_config 0.3.0 Locale#::user_defaultrust-analyzer cargo locale_config 0.3.0 impl#[Locale]user_default().());
694 }
695
696 thread_localrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/local/thread_local!!(
697 static CURRENT_LOCALErust-analyzer cargo locale_config 0.3.0 CURRENT_LOCALE.: RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#<Localerust-analyzer cargo locale_config 0.3.0 Locale#> = RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]new().(Localerust-analyzer cargo locale_config 0.3.0 Locale#::global_defaultrust-analyzer cargo locale_config 0.3.0 impl#[Locale]global_default().())
698 );
699
700 // NOTE: Cgi-style environment variable HTTP_ACCEPT_LANGUAGE is unlikely to be defined at any other
701 // time than when actually executing in CGI, so we can relatively safely always interpret it.
702 mod cgirust-analyzer cargo locale_config 0.3.0 cgi/;
703
704 // NOTE: Unix-style environment variables are actually inspected everywhere, because many users
705 // have them, because some software only uses those even on Windows and other systems.
706 mod unixrust-analyzer cargo locale_config 0.3.0 unix/;
707
708 // NOTE: Functions used exist from Vista on only
709 #[cfg(target_family = "windows")]
710 mod win32;
711
712 // Emscripten support
713 #[cfg(target_os = "emscripten")]
714 mod emscripten;
715
716 // macOS support
717 #[cfg(target_os = "macos")]
718 mod macos;
719
720 static INITIALISERSrust-analyzer cargo locale_config 0.3.0 INITIALISERS.: &'static [fn() -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Localerust-analyzer cargo locale_config 0.3.0 Locale#>] = &[
721 cgirust-analyzer cargo locale_config 0.3.0 cgi/::system_localerust-analyzer cargo locale_config 0.3.0 cgi/system_locale().,
722 unixrust-analyzer cargo locale_config 0.3.0 unix/::system_localerust-analyzer cargo locale_config 0.3.0 unix/system_locale().,
723 #[cfg(target_family = "windows")] win32::system_locale,
724 #[cfg(target_os = "emscripten")] emscripten::system_locale,
725 #[cfg(target_os = "macos")] macos::system_locale,
726 ];
727
728 fn system_localerust-analyzer cargo locale_config 0.3.0 system_locale().() -> Localerust-analyzer cargo locale_config 0.3.0 Locale# {
729 for f in INITIALISERSrust-analyzer cargo locale_config 0.3.0 INITIALISERS. {
730 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(l) = f() {
731 return l;
732 }
733 }
734 return Localerust-analyzer cargo locale_config 0.3.0 Locale#::invariantrust-analyzer cargo locale_config 0.3.0 impl#[Locale]invariant().();
735 }
736
737 // --------------------------------- ERRORS ------------------------------------
738
739 /// Errors that may be returned by `locale_config`.
740 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:,Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:,Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:,PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:,Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)]
741 pub enum Errorrust-analyzer cargo locale_config 0.3.0 Error# {
742 /// Provided definition was not well formed.
743 ///
744 /// This is returned when provided configuration string does not match even the rather loose
745 /// definition for language range from [RFC4647] or the composition format used by `Locale`.
746 ///
747 /// [RFC4647]: https://www.rfc-editor.org/rfc/rfc4647.txt
748 NotWellFormedrust-analyzer cargo locale_config 0.3.0 Error#NotWellFormed#,
749 /// Placeholder for adding more errors in future. **Do not match!**.
750 __NonExhaustiverust-analyzer cargo locale_config 0.3.0 Error#__NonExhaustive#,
751 }
752
753 impl ::stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for Errorrust-analyzer cargo locale_config 0.3.0 Error# {
754 fn fmtrust-analyzer cargo locale_config 0.3.0 impl#[Error][Display]fmt().(&self, out: &mut ::stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> ::stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
755 use ::stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#;
756 out.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().(self.descriptionrust-analyzer cargo locale_config 0.3.0 impl#[Error][Error]description().())
757 }
758 }
759
760 impl ::stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# for Errorrust-analyzer cargo locale_config 0.3.0 Error# {
761 fn descriptionrust-analyzer cargo locale_config 0.3.0 impl#[Error][Error]description().(&self) -> &str {
762 match self {
763 &Errorrust-analyzer cargo locale_config 0.3.0 Error#::NotWellFormedrust-analyzer cargo locale_config 0.3.0 Error#NotWellFormed# => "Language tag is not well-formed.",
764 // this is exception: here we do want exhaustive match so we don't publish version with
765 // missing descriptions by mistake.
766 &Errorrust-analyzer cargo locale_config 0.3.0 Error#::__NonExhaustiverust-analyzer cargo locale_config 0.3.0 Error#__NonExhaustive# => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Placeholder error must not be instantiated!"),
767 }
768 }
769 }
770
771 /// Convenience Result alias.
772 type Resultrust-analyzer cargo locale_config 0.3.0 Result#<T> = ::stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, Errorrust-analyzer cargo locale_config 0.3.0 Error#>;
773
774 // --------------------------------- TESTS -------------------------------------
775
776 #[cfg(test)]
777 mod testrust-analyzer cargo locale_config 0.3.0 test/ {
778 use superrust-analyzer cargo locale_config 0.3.0 crate/::LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#;
779 use superrust-analyzer cargo locale_config 0.3.0 crate/::Localerust-analyzer cargo locale_config 0.3.0 Locale#;
780 use superrust-analyzer cargo locale_config 0.3.0 crate/::is_ownedrust-analyzer cargo locale_config 0.3.0 is_owned().;
781 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::FromIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/FromIterator#;
782
783 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
784 fn simple_valid_lang_rangesrust-analyzer cargo locale_config 0.3.0 test/simple_valid_lang_ranges().() {
785 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("en-US", LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().("en-US").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_refrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`][`AsRef<str>`]as_ref().());
786 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("en-US", LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().("EN-US").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_refrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`][`AsRef<str>`]as_ref().());
787 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("en", LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().("en").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_refrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`][`AsRef<str>`]as_ref().());
788 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("eng-Latn-840", LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().("eng-Latn-840").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_refrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`][`AsRef<str>`]as_ref().());
789 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("english", LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().("English").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_refrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`][`AsRef<str>`]as_ref().());
790 }
791
792 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
793 fn wildcard_lang_rangesrust-analyzer cargo locale_config 0.3.0 test/wildcard_lang_ranges().() {
794 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("*", LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().("*").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_refrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`][`AsRef<str>`]as_ref().());
795 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("zh-*", LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().("zh-*").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_refrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`][`AsRef<str>`]as_ref().());
796 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("zh-*-CN", LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().("zh-*-cn").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_refrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`][`AsRef<str>`]as_ref().());
797 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("en-*-simple-*", LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().("En-*-Simple-*").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_refrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`][`AsRef<str>`]as_ref().());
798 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("zh-Hans-*", LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().("zh-hans-*").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_refrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`][`AsRef<str>`]as_ref().());
799 }
800
801 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
802 fn complex_valid_lang_rangesrust-analyzer cargo locale_config 0.3.0 test/complex_valid_lang_ranges().() {
803 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("de-DE-u-email-co-phonebk-x-linux",
804 LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().("de-DE-u-email-co-phonebk-x-linux").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_refrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`][`AsRef<str>`]as_ref().());
805 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("vi-VN-u-fw-mon-hc-h24-ms-metric",
806 LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().("vi-vn-u-fw-mon-hc-h24-ms-metric").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_refrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`][`AsRef<str>`]as_ref().());
807 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("sl-Cyrl-YU-rozaj-solba-1994-b-1234-a-foobar-x-b-1234-a-foobar",
808 LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().("sl-Cyrl-YU-rozaj-solba-1994-b-1234-a-Foobar-x-b-1234-a-Foobar").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_refrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`][`AsRef<str>`]as_ref().());
809 }
810
811 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
812 fn invalid_lang_range_invalid_charrust-analyzer cargo locale_config 0.3.0 test/invalid_lang_range_invalid_char().() {
813 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().("not a range").is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
814 }
815
816 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
817 fn invalid_lang_range_long_elementrust-analyzer cargo locale_config 0.3.0 test/invalid_lang_range_long_element().() {
818 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().("de-DE-u-email-co-phonebook-x-linux").is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
819 }
820
821 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
822 fn invalid_lang_range_leading_numberrust-analyzer cargo locale_config 0.3.0 test/invalid_lang_range_leading_number().() {
823 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().("840").is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
824 }
825
826 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
827 fn invalid_lang_range_bad_asteriskrust-analyzer cargo locale_config 0.3.0 test/invalid_lang_range_bad_asterisk().() {
828 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().("e*-US").is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
829 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().("en-*s").is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
830 }
831
832 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
833 fn normal_lang_rangerust-analyzer cargo locale_config 0.3.0 test/normal_lang_range().() {
834 // Check that the string is not copied if the tag is canonical
835 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_ownedrust-analyzer cargo locale_config 0.3.0 is_owned().(&LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().("en-US").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().languagerust-analyzer cargo locale_config 0.3.0 LanguageRange#language.));
836 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_ownedrust-analyzer cargo locale_config 0.3.0 is_owned().(&LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().("en").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().languagerust-analyzer cargo locale_config 0.3.0 LanguageRange#language.));
837 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_ownedrust-analyzer cargo locale_config 0.3.0 is_owned().(&LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().("zh-Hant-CN").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().languagerust-analyzer cargo locale_config 0.3.0 LanguageRange#language.));
838 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_ownedrust-analyzer cargo locale_config 0.3.0 is_owned().(&LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().("cs-CZ-x-ds-002e").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().languagerust-analyzer cargo locale_config 0.3.0 LanguageRange#language.));
839 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_ownedrust-analyzer cargo locale_config 0.3.0 is_owned().(&LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().("czech").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().languagerust-analyzer cargo locale_config 0.3.0 LanguageRange#language.));
840 }
841
842 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
843 fn locale_simplerust-analyzer cargo locale_config 0.3.0 test/locale_simple().() {
844 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("en-US", Localerust-analyzer cargo locale_config 0.3.0 Locale#::newrust-analyzer cargo locale_config 0.3.0 impl#[Locale]new().("en-US").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_refrust-analyzer cargo locale_config 0.3.0 impl#[Locale][`AsRef<str>`]as_ref().());
845 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("zh-Hant", Localerust-analyzer cargo locale_config 0.3.0 Locale#::newrust-analyzer cargo locale_config 0.3.0 impl#[Locale]new().("zh-hant").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_refrust-analyzer cargo locale_config 0.3.0 impl#[Locale][`AsRef<str>`]as_ref().());
846 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("de-*", Localerust-analyzer cargo locale_config 0.3.0 Locale#::newrust-analyzer cargo locale_config 0.3.0 impl#[Locale]new().("de-*").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_refrust-analyzer cargo locale_config 0.3.0 impl#[Locale][`AsRef<str>`]as_ref().());
847 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(Localerust-analyzer cargo locale_config 0.3.0 Locale#::newrust-analyzer cargo locale_config 0.3.0 impl#[Locale]new().("invalid!").is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
848 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(Localerust-analyzer cargo locale_config 0.3.0 Locale#::newrust-analyzer cargo locale_config 0.3.0 impl#[Locale]new().("hΔ±-Δ°N").is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
849 }
850
851 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
852 fn locale_listrust-analyzer cargo locale_config 0.3.0 test/locale_list().() {
853 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("cs-CZ,en-GB,en,*", Localerust-analyzer cargo locale_config 0.3.0 Locale#::newrust-analyzer cargo locale_config 0.3.0 impl#[Locale]new().("cs-cz,en-gb,en,*").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_refrust-analyzer cargo locale_config 0.3.0 impl#[Locale][`AsRef<str>`]as_ref().());
854 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("cs-CZ,engrish", Localerust-analyzer cargo locale_config 0.3.0 Locale#::newrust-analyzer cargo locale_config 0.3.0 impl#[Locale]new().("cs-cz,engrish").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_refrust-analyzer cargo locale_config 0.3.0 impl#[Locale][`AsRef<str>`]as_ref().());
855 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(Localerust-analyzer cargo locale_config 0.3.0 Locale#::newrust-analyzer cargo locale_config 0.3.0 impl#[Locale]new().("cs-cz,hΔ±-Δ°N").is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
856 }
857
858 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
859 fn locale_categoryrust-analyzer cargo locale_config 0.3.0 test/locale_category().() {
860 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("cs-CZ,messages=en-GB",
861 Localerust-analyzer cargo locale_config 0.3.0 Locale#::newrust-analyzer cargo locale_config 0.3.0 impl#[Locale]new().("cs-CZ,messages=en-GB").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_refrust-analyzer cargo locale_config 0.3.0 impl#[Locale][`AsRef<str>`]as_ref().());
862 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("zh-Hant,time=ja-JP,measurement=en-US",
863 Localerust-analyzer cargo locale_config 0.3.0 Locale#::newrust-analyzer cargo locale_config 0.3.0 impl#[Locale]new().("zh-hant,TIME=ja-jp,meaSURement=en-US").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_refrust-analyzer cargo locale_config 0.3.0 impl#[Locale][`AsRef<str>`]as_ref().());
864 // the first item must be plain language tag
865 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(Localerust-analyzer cargo locale_config 0.3.0 Locale#::newrust-analyzer cargo locale_config 0.3.0 impl#[Locale]new().("messages=pl").is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
866 // adding general alternate should not help
867 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(Localerust-analyzer cargo locale_config 0.3.0 Locale#::newrust-analyzer cargo locale_config 0.3.0 impl#[Locale]new().("numeric=de,fr-FR").is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
868 }
869
870 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
871 fn locale_dupsrust-analyzer cargo locale_config 0.3.0 test/locale_dups().() {
872 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("cs-CZ,en,de-AT", Localerust-analyzer cargo locale_config 0.3.0 Locale#::newrust-analyzer cargo locale_config 0.3.0 impl#[Locale]new().("cs-CZ,en,de-AT,en").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_refrust-analyzer cargo locale_config 0.3.0 impl#[Locale][`AsRef<str>`]as_ref().());
873 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("en-US,en", Localerust-analyzer cargo locale_config 0.3.0 Locale#::newrust-analyzer cargo locale_config 0.3.0 impl#[Locale]new().("en-us,en-US,EN,eN-Us,en").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_refrust-analyzer cargo locale_config 0.3.0 impl#[Locale][`AsRef<str>`]as_ref().());
874 }
875
876 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
877 fn locale_category_dupsrust-analyzer cargo locale_config 0.3.0 test/locale_category_dups().() {
878 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("cs-CZ",
879 Localerust-analyzer cargo locale_config 0.3.0 Locale#::newrust-analyzer cargo locale_config 0.3.0 impl#[Locale]new().("cs-CZ,messages=cs-CZ,time=cs-cz,collate=CS-cz").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_refrust-analyzer cargo locale_config 0.3.0 impl#[Locale][`AsRef<str>`]as_ref().());
880 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("de-AT,en-AU",
881 Localerust-analyzer cargo locale_config 0.3.0 Locale#::newrust-analyzer cargo locale_config 0.3.0 impl#[Locale]new().("de-AT,en-AU,messages=de-AT").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_refrust-analyzer cargo locale_config 0.3.0 impl#[Locale][`AsRef<str>`]as_ref().());
882 // category overrides override, so don't drop if they are only equal to alternates
883 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("de-AT,en-AU,messages=en-AU",
884 Localerust-analyzer cargo locale_config 0.3.0 Locale#::newrust-analyzer cargo locale_config 0.3.0 impl#[Locale]new().("de-AT,en-AU,messages=en-AU").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_refrust-analyzer cargo locale_config 0.3.0 impl#[Locale][`AsRef<str>`]as_ref().());
885 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("hi-IN,time=en-IN",
886 Localerust-analyzer cargo locale_config 0.3.0 Locale#::newrust-analyzer cargo locale_config 0.3.0 impl#[Locale]new().("hi-IN,time=en-IN,TIME=EN-in,TiMe=En-iN").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_refrust-analyzer cargo locale_config 0.3.0 impl#[Locale][`AsRef<str>`]as_ref().());
887 }
888
889 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
890 fn unix_tagsrust-analyzer cargo locale_config 0.3.0 test/unix_tags().() {
891 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("cs-CZ", LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::from_unixrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]from_unix().("cs_CZ.UTF-8").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_refrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`][`AsRef<str>`]as_ref().());
892 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("sr-RS-ijekavsk", LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::from_unixrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]from_unix().("sr_RS@ijekavian").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_refrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`][`AsRef<str>`]as_ref().());
893 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("sr-Latn-ijekavsk", LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::from_unixrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]from_unix().("sr.UTF-8@ijekavianlatin").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_refrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`][`AsRef<str>`]as_ref().());
894 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("en-Arab", LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::from_unixrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]from_unix().("en@arabic").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_refrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`][`AsRef<str>`]as_ref().());
895 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("en-Arab", LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::from_unixrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]from_unix().("en.UTF-8@arabic").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_refrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`][`AsRef<str>`]as_ref().());
896 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("de-DE", LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::from_unixrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]from_unix().("DE_de.UTF-8@euro").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_refrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`][`AsRef<str>`]as_ref().());
897 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("ssy-ER", LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::from_unixrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]from_unix().("aa_ER@saaho").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_refrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`][`AsRef<str>`]as_ref().());
898 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::from_unixrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]from_unix().("foo_BAR").is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
899 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::from_unixrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]from_unix().("[email protected]").is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
900 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("", LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::from_unixrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]from_unix().("C").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_refrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`][`AsRef<str>`]as_ref().());
901 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("", LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::from_unixrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]from_unix().("C.UTF-8").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_refrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`][`AsRef<str>`]as_ref().());
902 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("", LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::from_unixrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]from_unix().("C.ISO-8859-1").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_refrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`][`AsRef<str>`]as_ref().());
903 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("", LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::from_unixrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]from_unix().("POSIX").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_refrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`][`AsRef<str>`]as_ref().());
904 }
905
906 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
907 fn category_tag_listrust-analyzer cargo locale_config 0.3.0 test/category_tag_list().() {
908 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
909 Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::from_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`][`FromIterator<T>`]from_iter().(Localerust-analyzer cargo locale_config 0.3.0 Locale#::newrust-analyzer cargo locale_config 0.3.0 impl#[Locale]new().("cs-CZ,messages=en-GB,time=de-DE,collate=en-US").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().tagsrust-analyzer cargo locale_config 0.3.0 impl#[Locale]tags().()),
910 &[(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().("cs-CZ").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()),
911 (Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("messages"), LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().("en-GB").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()),
912 (Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("time"), LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().("de-DE").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()),
913 (Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("collate"), LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().("en-US").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()),
914 ]);
915 }
916
917 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
918 fn tag_list_forrust-analyzer cargo locale_config 0.3.0 test/tag_list_for().() {
919 let locale = Localerust-analyzer cargo locale_config 0.3.0 Locale#::newrust-analyzer cargo locale_config 0.3.0 impl#[Locale]new().("cs-CZ,messages=en-GB,time=de-DE,sk-SK,pl-PL").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
920 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
921 Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::from_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`][`FromIterator<T>`]from_iter().(locale.tags_forrust-analyzer cargo locale_config 0.3.0 impl#[Locale]tags_for().("messages")),
922 &[LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().("en-GB").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
923 LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().("cs-CZ").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
924 LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().("sk-SK").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
925 LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().("pl-PL").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
926 ]);
927 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
928 Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::from_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`][`FromIterator<T>`]from_iter().(locale.tags_forrust-analyzer cargo locale_config 0.3.0 impl#[Locale]tags_for().("time")),
929 &[LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().("de-DE").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
930 LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().("cs-CZ").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
931 LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().("sk-SK").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
932 LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().("pl-PL").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
933 ]);
934 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
935 Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::from_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`][`FromIterator<T>`]from_iter().(locale.tags_forrust-analyzer cargo locale_config 0.3.0 impl#[Locale]tags_for().("measurement")),
936 &[LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().("cs-CZ").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
937 LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().("sk-SK").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
938 LanguageRangerust-analyzer cargo locale_config 0.3.0 LanguageRange#::newrust-analyzer cargo locale_config 0.3.0 impl#[`LanguageRange<'a>`]new().("pl-PL").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
939 ]);
940 }
941 }