From cbaa89e1a2fbced31672376ae309dffabfd1b01d Mon Sep 17 00:00:00 2001 From: jedel1043 Date: Fri, 22 Sep 2023 11:24:18 -0600 Subject: [PATCH] Document and clippify --- components/plurals/src/provider.rs | 16 ++++++++++++++-- .../datagen/src/transform/cldr/cldr_serde/mod.rs | 2 +- .../transform/cldr/cldr_serde/plural_ranges.rs | 2 +- .../datagen/src/transform/cldr/plurals/mod.rs | 9 ++++----- tools/ffi_coverage/src/allowlist.rs | 2 ++ 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/components/plurals/src/provider.rs b/components/plurals/src/provider.rs index 6b216269983..bffcae251b4 100644 --- a/components/plurals/src/provider.rs +++ b/components/plurals/src/provider.rs @@ -16,7 +16,6 @@ //! Read more about data providers: [`icu_provider`] use crate::rules::runtime::ast::Rule; -use crate::PluralCategory; use icu_provider::prelude::*; use icu_provider::DataMarker; use zerovec::ZeroMap2d; @@ -41,9 +40,9 @@ const _: () = { icu_plurals_data::make_provider!(Baked); icu_plurals_data::impl_plurals_ordinal_v1!(Baked); icu_plurals_data::impl_plurals_cardinal_v1!(Baked); + icu_plurals_data::impl_plurals_ranges_v1!(Baked); }; -#[cfg(doc)] use crate::PluralCategory; /// Plural rule strings conforming to UTS 35 syntax. Includes separate fields for five of the six @@ -91,6 +90,18 @@ impl DataMarker for ErasedPluralRulesV1Marker { type Yokeable = PluralRulesV1<'static>; } +/// Plural categories for ranges. +/// +/// Obtains the plural category of a range from the categories of its endpoints. It is required that +/// the start value must be strictly less than the end value, and both values must be strictly positive. +/// +/// More information: +/// +///
+/// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways, +/// including in SemVer minor releases. While the serde representation of data structs is guaranteed +/// to be stable, their Rust representation might not be. Use with caution. +///
#[icu_provider::data_struct(PluralRangesV1Marker = "plurals/ranges@1")] #[derive(Clone, PartialEq, Debug)] #[cfg_attr( @@ -101,6 +112,7 @@ impl DataMarker for ErasedPluralRulesV1Marker { #[cfg_attr(feature = "serde", derive(serde::Deserialize))] #[yoke(prove_covariance_manually)] pub struct PluralRangesV1<'data> { + /// Map between the categories of the endpoints of a range and its corresponding category. #[cfg_attr(feature = "serde", serde(borrow))] pub ranges: ZeroMap2d<'data, PluralCategory, PluralCategory, PluralCategory>, } diff --git a/provider/datagen/src/transform/cldr/cldr_serde/mod.rs b/provider/datagen/src/transform/cldr/cldr_serde/mod.rs index 0ba11c38762..97633963eac 100644 --- a/provider/datagen/src/transform/cldr/cldr_serde/mod.rs +++ b/provider/datagen/src/transform/cldr/cldr_serde/mod.rs @@ -26,8 +26,8 @@ pub mod locale_resource; pub mod numbering_systems; pub mod numbers; pub mod parent_locales; -pub mod plurals; pub mod plural_ranges; +pub mod plurals; pub mod time_zones; #[cfg(feature = "icu_transliterate")] pub mod transforms; diff --git a/provider/datagen/src/transform/cldr/cldr_serde/plural_ranges.rs b/provider/datagen/src/transform/cldr/cldr_serde/plural_ranges.rs index bcc036c9863..255cf0acef9 100644 --- a/provider/datagen/src/transform/cldr/cldr_serde/plural_ranges.rs +++ b/provider/datagen/src/transform/cldr/cldr_serde/plural_ranges.rs @@ -56,7 +56,7 @@ impl<'de> Deserialize<'de> for PluralRange { let v = v.strip_prefix("pluralRange-start-").ok_or_else(|| { E::custom("expected prefix `pluralRange-start-` before start category") })?; - let (start, v) = v.split_once("-").ok_or_else(|| { + let (start, v) = v.split_once('-').ok_or_else(|| { E::custom("missing token `-` between start and end categories") })?; let end = v diff --git a/provider/datagen/src/transform/cldr/plurals/mod.rs b/provider/datagen/src/transform/cldr/plurals/mod.rs index 02553f63cee..0267f3ffd96 100644 --- a/provider/datagen/src/transform/cldr/plurals/mod.rs +++ b/provider/datagen/src/transform/cldr/plurals/mod.rs @@ -5,7 +5,6 @@ use std::collections::BTreeMap; use crate::transform::cldr::cldr_serde; -use crate::transform::cldr::cldr_serde::plural_ranges::PluralRange; use icu_plurals::rules::runtime::ast::Rule; use icu_plurals::{provider::*, PluralCategory}; use icu_provider::datagen::IterableDataProvider; @@ -132,10 +131,10 @@ impl From<&cldr_serde::plural_ranges::LocalePluralRanges> for PluralRangesV1<'st } let mut map: BTreeMap> = BTreeMap::new(); - for (PluralRange { start, end }, result) in &other.0 { - let start = convert(&start); - let end = convert(&end); - let result = convert(&result); + for (range, result) in &other.0 { + let start = convert(&range.start); + let end = convert(&range.end); + let result = convert(result); // // "If there is no value for a pair, the default result is end." diff --git a/tools/ffi_coverage/src/allowlist.rs b/tools/ffi_coverage/src/allowlist.rs index 9b7e1afd2bc..01d71a5de0e 100644 --- a/tools/ffi_coverage/src/allowlist.rs +++ b/tools/ffi_coverage/src/allowlist.rs @@ -416,6 +416,8 @@ lazy_static::lazy_static! { "icu::plurals::PluralCategory::all", // associated type "icu::plurals::PluralOperands::Err", + // internal to provider but defined in root + "icu::plurals::PluralCategoryULE", // locid macros "icu::locid::langid",