@@ -84,6 +84,17 @@ mod operands;
84
84
pub mod provider;
85
85
pub mod rules;
86
86
87
+ #[ doc( hidden) ]
88
+ #[ cfg( feature = "data" ) ]
89
+ pub mod data {
90
+ include ! ( core:: env!( "MACROS_RS" ) ) ;
91
+
92
+ use crate as icu_plurals;
93
+ pub ( crate ) struct Provider ;
94
+ impl_plurals_ordinal_v1 ! ( Provider ) ;
95
+ impl_plurals_cardinal_v1 ! ( Provider ) ;
96
+ }
97
+
87
98
use core:: cmp:: { Ord , PartialOrd } ;
88
99
pub use error:: PluralsError ;
89
100
use icu_provider:: prelude:: * ;
@@ -289,30 +300,30 @@ impl PluralCategory {
289
300
pub struct PluralRules ( DataPayload < ErasedPluralRulesV1Marker > ) ;
290
301
291
302
impl PluralRules {
292
- /// Constructs a new `PluralRules` for a given locale, [`type`] and [`data provider`].
293
- ///
294
- /// This constructor will fail if the [`Data Provider`] does not have the data.
295
- ///
296
- /// [📚 Help choosing a constructor](icu_provider::constructors)
297
- /// <div class="stab unstable">
298
- /// ⚠️ The bounds on this function may change over time, including in SemVer minor releases.
299
- /// </div>
300
- ///
301
- /// # Examples
302
- ///
303
- /// ```
304
- /// use icu::locid::locale;
305
- /// use icu::plurals::{PluralRuleType, PluralRules};
306
- ///
307
- /// let _ = PluralRules::try_new_unstable(
308
- /// &icu_testdata::unstable(),
309
- /// &locale!("en").into(),
310
- /// PluralRuleType::Cardinal,
311
- /// );
312
- /// ```
313
- ///
314
- /// [`type`]: PluralRuleType
315
- /// [`data provider`]: icu_provider
303
+
304
+ icu_provider :: gen_any_buffer_data_constructors! (
305
+ locale : include ,
306
+ rule_type : PluralRuleType ,
307
+ error : PluralsError ,
308
+ /// Constructs a new `PluralRules` for a given locale, [`type`] and [`data provider`].
309
+ ///
310
+ /// # Examples
311
+ ///
312
+ /// ```
313
+ /// use icu::locid::locale;
314
+ /// use icu::plurals::{PluralRuleType, PluralRules};
315
+ ///
316
+ /// let _ = PluralRules::try_new(
317
+ /// &locale!("en").into(),
318
+ /// PluralRuleType::Cardinal,
319
+ /// );
320
+ /// ```
321
+ ///
322
+ /// [`type`]: PluralRuleType
323
+ /// [`data provider`]: icu_provider
324
+ ) ;
325
+
326
+ # [ doc = icu_provider:: gen_any_buffer_unstable_docs! ( UNSTABLE , Self :: try_new ) ]
316
327
pub fn try_new_unstable < D > (
317
328
data_provider : & D ,
318
329
locale : & DataLocale ,
@@ -327,44 +338,42 @@ impl PluralRules {
327
338
}
328
339
}
329
340
330
- icu_provider:: gen_any_buffer_constructors !(
341
+ icu_provider:: gen_any_buffer_data_constructors !(
331
342
locale: include,
332
- rule_type: PluralRuleType ,
333
- error: PluralsError
343
+ options: skip,
344
+ error: PluralsError ,
345
+ /// Constructs a new `PluralRules` for a given locale for cardinal numbers.
346
+ ///
347
+ /// Cardinal plural forms express quantities of units such as time, currency or distance,
348
+ /// used in conjunction with a number expressed in decimal digits (i.e. "2", not "two").
349
+ ///
350
+ /// For example, English has two forms for cardinals:
351
+ ///
352
+ /// * [`One`]: `1 day`
353
+ /// * [`Other`]: `0 days`, `2 days`, `10 days`, `0.3 days`
354
+ ///
355
+ /// # Examples
356
+ ///
357
+ /// ```
358
+ /// use icu::locid::locale;
359
+ /// use icu::plurals::{PluralCategory, PluralRules};
360
+ ///
361
+ /// let rules = PluralRules::try_new_cardinal(&locale!("ru").into()).expect("Data should be present");
362
+ ///
363
+ /// assert_eq!(rules.category_for(2_usize), PluralCategory::Few);
364
+ /// ```
365
+ ///
366
+ /// [`One`]: PluralCategory::One
367
+ /// [`Other`]: PluralCategory::Other
368
+ functions: [
369
+ Self :: try_new_cardinal_unstable,
370
+ try_new_cardinal_with_any_provider,
371
+ try_new_cardinal_with_buffer_provider,
372
+ try_new_cardinal,
373
+ ]
334
374
) ;
335
375
336
- /// Constructs a new `PluralRules` for a given locale for cardinal numbers.
337
- ///
338
- /// Cardinal plural forms express quantities of units such as time, currency or distance,
339
- /// used in conjunction with a number expressed in decimal digits (i.e. "2", not "two").
340
- ///
341
- /// For example, English has two forms for cardinals:
342
- ///
343
- /// * [`One`]: `1 day`
344
- /// * [`Other`]: `0 days`, `2 days`, `10 days`, `0.3 days`
345
- ///
346
- /// [📚 Help choosing a constructor](icu_provider::constructors)
347
- /// <div class="stab unstable">
348
- /// ⚠️ The bounds on this function may change over time, including in SemVer minor releases.
349
- /// </div>
350
- ///
351
- /// # Examples
352
- ///
353
- /// ```
354
- /// use icu::locid::locale;
355
- /// use icu::plurals::{PluralCategory, PluralRules};
356
- ///
357
- /// let rules = PluralRules::try_new_cardinal_unstable(
358
- /// &icu_testdata::unstable(),
359
- /// &locale!("ru").into(),
360
- /// )
361
- /// .expect("Data should be present");
362
- ///
363
- /// assert_eq!(rules.category_for(2_usize), PluralCategory::Few);
364
- /// ```
365
- ///
366
- /// [`One`]: PluralCategory::One
367
- /// [`Other`]: PluralCategory::Other
376
+ #[ doc = icu_provider:: gen_any_buffer_unstable_docs!( UNSTABLE , Self :: try_new_cardinal) ]
368
377
pub fn try_new_cardinal_unstable < D > (
369
378
data_provider : & D ,
370
379
locale : & DataLocale ,
@@ -383,52 +392,49 @@ impl PluralRules {
383
392
) )
384
393
}
385
394
386
- icu_provider:: gen_any_buffer_constructors !(
395
+ icu_provider:: gen_any_buffer_data_constructors !(
387
396
locale: include,
388
397
options: skip,
389
398
error: PluralsError ,
399
+ /// Constructs a new `PluralRules` for a given locale for ordinal numbers.
400
+ ///
401
+ /// Ordinal plural forms denote the order of items in a set and are always integers.
402
+ ///
403
+ /// For example, English has four forms for ordinals:
404
+ ///
405
+ /// * [`One`]: `1st floor`, `21st floor`, `101st floor`
406
+ /// * [`Two`]: `2nd floor`, `22nd floor`, `102nd floor`
407
+ /// * [`Few`]: `3rd floor`, `23rd floor`, `103rd floor`
408
+ /// * [`Other`]: `4th floor`, `11th floor`, `96th floor`
409
+ ///
410
+ /// # Examples
411
+ ///
412
+ /// ```
413
+ /// use icu::locid::locale;
414
+ /// use icu::plurals::{PluralCategory, PluralRules};
415
+ ///
416
+ /// let rules = PluralRules::try_new_ordinal_unstable(
417
+ /// &icu_testdata::unstable(),
418
+ /// &locale!("ru").into(),
419
+ /// )
420
+ /// .expect("Data should be present");
421
+ ///
422
+ /// assert_eq!(rules.category_for(2_usize), PluralCategory::Other);
423
+ /// ```
424
+ ///
425
+ /// [`One`]: PluralCategory::One
426
+ /// [`Two`]: PluralCategory::Two
427
+ /// [`Few`]: PluralCategory::Few
428
+ /// [`Other`]: PluralCategory::Other
390
429
functions: [
391
- Self :: try_new_cardinal_unstable,
392
- try_new_cardinal_with_any_provider,
393
- try_new_cardinal_with_buffer_provider
430
+ Self :: try_new_ordinal_unstable,
431
+ try_new_ordinal_with_any_provider,
432
+ try_new_ordinal_with_buffer_provider,
433
+ try_new_ordinal,
394
434
]
395
435
) ;
396
436
397
- /// Constructs a new `PluralRules` for a given locale for ordinal numbers.
398
- ///
399
- /// Ordinal plural forms denote the order of items in a set and are always integers.
400
- ///
401
- /// For example, English has four forms for ordinals:
402
- ///
403
- /// * [`One`]: `1st floor`, `21st floor`, `101st floor`
404
- /// * [`Two`]: `2nd floor`, `22nd floor`, `102nd floor`
405
- /// * [`Few`]: `3rd floor`, `23rd floor`, `103rd floor`
406
- /// * [`Other`]: `4th floor`, `11th floor`, `96th floor`
407
- ///
408
- /// [📚 Help choosing a constructor](icu_provider::constructors)
409
- /// <div class="stab unstable">
410
- /// ⚠️ The bounds on this function may change over time, including in SemVer minor releases.
411
- /// </div>
412
- ///
413
- /// # Examples
414
- ///
415
- /// ```
416
- /// use icu::locid::locale;
417
- /// use icu::plurals::{PluralCategory, PluralRules};
418
- ///
419
- /// let rules = PluralRules::try_new_ordinal_unstable(
420
- /// &icu_testdata::unstable(),
421
- /// &locale!("ru").into(),
422
- /// )
423
- /// .expect("Data should be present");
424
- ///
425
- /// assert_eq!(rules.category_for(2_usize), PluralCategory::Other);
426
- /// ```
427
- ///
428
- /// [`One`]: PluralCategory::One
429
- /// [`Two`]: PluralCategory::Two
430
- /// [`Few`]: PluralCategory::Few
431
- /// [`Other`]: PluralCategory::Other
437
+ #[ doc = icu_provider:: gen_any_buffer_unstable_docs!( UNSTABLE , Self :: try_new_ordinal) ]
432
438
pub fn try_new_ordinal_unstable < D > (
433
439
data_provider : & D ,
434
440
locale : & DataLocale ,
@@ -447,17 +453,6 @@ impl PluralRules {
447
453
) )
448
454
}
449
455
450
- icu_provider:: gen_any_buffer_constructors!(
451
- locale: include,
452
- options: skip,
453
- error: PluralsError ,
454
- functions: [
455
- Self :: try_new_ordinal_unstable,
456
- try_new_ordinal_with_any_provider,
457
- try_new_ordinal_with_buffer_provider
458
- ]
459
- ) ;
460
-
461
456
/// Returns the [`Plural Category`] appropriate for the given number.
462
457
///
463
458
/// # Examples
0 commit comments