Skip to content

Commit

Permalink
Document and clippify
Browse files Browse the repository at this point in the history
  • Loading branch information
jedel1043 committed Sep 22, 2023
1 parent 4b976c9 commit cbaa89e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
16 changes: 14 additions & 2 deletions components/plurals/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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: <https://unicode.org/reports/tr35/tr35-numbers.html#Plural_Ranges>
///
/// <div class="stab unstable">
/// 🚧 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.
/// </div>
#[icu_provider::data_struct(PluralRangesV1Marker = "plurals/ranges@1")]
#[derive(Clone, PartialEq, Debug)]
#[cfg_attr(
Expand All @@ -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>,
}
Expand Down
2 changes: 1 addition & 1 deletion provider/datagen/src/transform/cldr/cldr_serde/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions provider/datagen/src/transform/cldr/plurals/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -132,10 +131,10 @@ impl From<&cldr_serde::plural_ranges::LocalePluralRanges> for PluralRangesV1<'st
}
let mut map: BTreeMap<PluralCategory, BTreeMap<PluralCategory, PluralCategory>> =
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);

// <https://unicode.org/reports/tr35/tr35-numbers.html#Plural_Ranges>
// "If there is no value for a <start,end> pair, the default result is end."
Expand Down
2 changes: 2 additions & 0 deletions tools/ffi_coverage/src/allowlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit cbaa89e

Please sign in to comment.