119119//! ```
120120//!
121121
122- use std:: collections:: HashMap ;
123122use unic_langid:: LanguageIdentifier ;
124123
125124#[ cfg( not( feature = "cldr" ) ) ]
@@ -141,11 +140,8 @@ pub fn filter_matches<'a, R: 'a + AsRef<LanguageIdentifier>, A: 'a + AsRef<Langu
141140) -> Vec < & ' a A > {
142141 let mut supported_locales = vec ! [ ] ;
143142
144- let mut av_map: HashMap < & ' a LanguageIdentifier , & ' a A > = HashMap :: new ( ) ;
145-
146- for av in available. iter ( ) {
147- av_map. insert ( av. as_ref ( ) , av) ;
148- }
143+ let mut available_locales: Vec < ( & LanguageIdentifier , & A ) > =
144+ available. iter ( ) . map ( |a| ( a. as_ref ( ) , a) ) . collect ( ) ;
149145
150146 for req in requested {
151147 let mut req = req. as_ref ( ) . to_owned ( ) ;
@@ -156,7 +152,7 @@ pub fn filter_matches<'a, R: 'a + AsRef<LanguageIdentifier>, A: 'a + AsRef<Langu
156152 let mut match_found = false ;
157153
158154 // 1) Try to find a simple (case-insensitive) string match for the request.
159- av_map . retain ( |key, value| {
155+ available_locales . retain ( |( key, value) | {
160156 if strategy != NegotiationStrategy :: Filtering && match_found {
161157 return true ;
162158 }
@@ -180,7 +176,7 @@ pub fn filter_matches<'a, R: 'a + AsRef<LanguageIdentifier>, A: 'a + AsRef<Langu
180176 match_found = false ;
181177
182178 // 2) Try to match against the available locales treated as ranges.
183- av_map . retain ( |key, value| {
179+ available_locales . retain ( |( key, value) | {
184180 if strategy != NegotiationStrategy :: Filtering && match_found {
185181 return true ;
186182 }
@@ -205,7 +201,7 @@ pub fn filter_matches<'a, R: 'a + AsRef<LanguageIdentifier>, A: 'a + AsRef<Langu
205201
206202 // 3) Try to match against a maximized version of the requested locale
207203 if req. add_likely_subtags ( ) {
208- av_map . retain ( |key, value| {
204+ available_locales . retain ( |( key, value) | {
209205 if strategy != NegotiationStrategy :: Filtering && match_found {
210206 return true ;
211207 }
@@ -231,7 +227,7 @@ pub fn filter_matches<'a, R: 'a + AsRef<LanguageIdentifier>, A: 'a + AsRef<Langu
231227
232228 // 4) Try to match against a variant as a range
233229 req. clear_variants ( ) ;
234- av_map . retain ( |key, value| {
230+ available_locales . retain ( |( key, value) | {
235231 if strategy != NegotiationStrategy :: Filtering && match_found {
236232 return true ;
237233 }
@@ -257,7 +253,7 @@ pub fn filter_matches<'a, R: 'a + AsRef<LanguageIdentifier>, A: 'a + AsRef<Langu
257253 // 5) Try to match against the likely subtag without region
258254 req. clear_region ( ) ;
259255 if req. add_likely_subtags ( ) {
260- av_map . retain ( |key, value| {
256+ available_locales . retain ( |( key, value) | {
261257 if strategy != NegotiationStrategy :: Filtering && match_found {
262258 return true ;
263259 }
@@ -283,7 +279,7 @@ pub fn filter_matches<'a, R: 'a + AsRef<LanguageIdentifier>, A: 'a + AsRef<Langu
283279
284280 // 6) Try to match against a region as a range
285281 req. clear_region ( ) ;
286- av_map . retain ( |key, value| {
282+ available_locales . retain ( |( key, value) | {
287283 if strategy != NegotiationStrategy :: Filtering && match_found {
288284 return true ;
289285 }
@@ -311,7 +307,7 @@ pub fn filter_matches<'a, R: 'a + AsRef<LanguageIdentifier>, A: 'a + AsRef<Langu
311307pub fn negotiate_languages <
312308 ' a ,
313309 R : ' a + AsRef < LanguageIdentifier > ,
314- A : ' a + AsRef < LanguageIdentifier > ,
310+ A : ' a + AsRef < LanguageIdentifier > + PartialEq ,
315311> (
316312 requested : & [ R ] ,
317313 available : & ' a [ A ] ,
@@ -325,7 +321,7 @@ pub fn negotiate_languages<
325321 if supported. is_empty ( ) {
326322 supported. push ( default) ;
327323 }
328- } else if !supported. iter ( ) . any ( |s| s . as_ref ( ) == default. as_ref ( ) ) {
324+ } else if !supported. contains ( & default) {
329325 supported. push ( default) ;
330326 }
331327 }
0 commit comments