@@ -37,11 +37,11 @@ use tinystr::TinyAsciiStr;
37
37
///
38
38
/// [UTS #35: Annex C, LocaleId Canonicalization]: http://unicode.org/reports/tr35/#LocaleId_Canonicalization
39
39
#[ derive( Debug ) ]
40
- pub struct LocaleCanonicalizer {
40
+ pub struct LocaleCanonicalizer < Expander = LocaleExpander > {
41
41
/// Data to support canonicalization.
42
42
aliases : DataPayload < AliasesV2Marker > ,
43
43
/// Likely subtags implementation for delegation.
44
- expander : LocaleExpander ,
44
+ expander : Expander ,
45
45
}
46
46
47
47
fn uts35_rule_matches < ' a , I > (
@@ -197,13 +197,13 @@ fn uts35_check_language_rules(
197
197
}
198
198
199
199
#[ cfg( feature = "compiled_data" ) ]
200
- impl Default for LocaleCanonicalizer {
200
+ impl Default for LocaleCanonicalizer < LocaleExpander > {
201
201
fn default ( ) -> Self {
202
202
Self :: new ( )
203
203
}
204
204
}
205
205
206
- impl LocaleCanonicalizer {
206
+ impl LocaleCanonicalizer < LocaleExpander > {
207
207
/// A constructor which creates a [`LocaleCanonicalizer`] from compiled data.
208
208
///
209
209
/// ✨ *Enabled with the `compiled_data` Cargo feature.*
@@ -235,14 +235,16 @@ impl LocaleCanonicalizer {
235
235
let expander = LocaleExpander :: try_new_unstable ( provider) ?;
236
236
Self :: try_new_with_expander_unstable ( provider, expander)
237
237
}
238
+ }
238
239
240
+ impl < Expander : AsRef < LocaleExpander > > LocaleCanonicalizer < Expander > {
239
241
/// Creates a [`LocaleCanonicalizer`] with a custom [`LocaleExpander`] and compiled data.
240
242
///
241
243
/// ✨ *Enabled with the `compiled_data` Cargo feature.*
242
244
///
243
245
/// [📚 Help choosing a constructor](icu_provider::constructors)
244
246
#[ cfg( feature = "compiled_data" ) ]
245
- pub const fn new_with_expander ( expander : LocaleExpander ) -> Self {
247
+ pub const fn new_with_expander ( expander : Expander ) -> Self {
246
248
Self {
247
249
aliases : DataPayload :: from_static_ref (
248
250
crate :: provider:: Baked :: SINGLETON_ALIASES_V2_MARKER ,
@@ -254,7 +256,7 @@ impl LocaleCanonicalizer {
254
256
#[ doc = icu_provider:: gen_any_buffer_unstable_docs!( UNSTABLE , Self :: new_with_expander) ]
255
257
pub fn try_new_with_expander_unstable < P > (
256
258
provider : & P ,
257
- expander : LocaleExpander ,
259
+ expander : Expander ,
258
260
) -> Result < Self , DataError >
259
261
where
260
262
P : DataProvider < AliasesV2Marker > + ?Sized ,
@@ -264,7 +266,7 @@ impl LocaleCanonicalizer {
264
266
Ok ( Self { aliases, expander } )
265
267
}
266
268
267
- icu_provider:: gen_any_buffer_data_constructors!( ( options: LocaleExpander ) -> error: DataError ,
269
+ icu_provider:: gen_any_buffer_data_constructors!( ( options: Expander ) -> error: DataError ,
268
270
functions: [
269
271
new_with_expander: skip,
270
272
try_new_with_expander_with_any_provider,
@@ -395,7 +397,10 @@ impl LocaleCanonicalizer {
395
397
} ;
396
398
397
399
locale. id . region = Some (
398
- match ( self . expander . maximize ( & mut maximized) , maximized. region ) {
400
+ match (
401
+ self . expander . as_ref ( ) . maximize ( & mut maximized) ,
402
+ maximized. region ,
403
+ ) {
399
404
( TransformResult :: Modified , Some ( candidate) )
400
405
if regions. iter ( ) . any ( |x| x == candidate) =>
401
406
{
0 commit comments