Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PluralRules FFI APIs and rust_links #6186

Merged
merged 6 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ffi/capi/bindings/c/PluralOperands.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions ffi/capi/bindings/cpp/icu4x/PluralOperands.d.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions ffi/capi/bindings/cpp/icu4x/PluralOperands.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions ffi/capi/bindings/dart/PluralOperands.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions ffi/capi/bindings/js/PluralOperands.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions ffi/capi/bindings/js/PluralOperands.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion ffi/capi/src/pluralrules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ pub mod ffi {
#[diplomat::rust_link(icu::plurals::PluralRules::try_new_cardinal, FnInStruct)]
#[diplomat::rust_link(icu::plurals::PluralRules::try_new, FnInStruct, hidden)]
#[diplomat::rust_link(icu::plurals::PluralRuleType, Enum, hidden)]
#[diplomat::rust_link(icu::plurals::PluralRulesOptions, Struct, hidden)]
#[diplomat::rust_link(icu::plurals::PluralRulesOptions::default, FnInStruct, hidden)]
#[diplomat::rust_link(icu::plurals::PluralRulesOptions::with_type, FnInStruct, hidden)]
#[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "cardinal")]
#[cfg(feature = "compiled_data")]
pub fn create_cardinal(locale: &Locale) -> Result<Box<PluralRules>, DataError> {
Expand Down Expand Up @@ -129,7 +132,6 @@ pub mod ffi {
&fixed_decimal::Decimal::try_from_utf8(s)?,
))))
}

/// Construct from a FixedDecimal
///
/// Retains at most 18 digits each from the integer and fraction parts.
Expand All @@ -138,6 +140,15 @@ pub mod ffi {
pub fn from_fixed_decimal(x: &crate::fixed_decimal::ffi::Decimal) -> Box<Self> {
Box::new(Self((&x.0).into()))
}

#[diplomat::rust_link(icu::plurals::PluralOperands::is_exactly_one, FnInStruct)]
pub fn is_exactly_one(&self) -> bool {
self.0.is_exactly_one()
}
#[diplomat::rust_link(icu::plurals::PluralOperands::is_exactly_zero, FnInStruct)]
pub fn is_exactly_zero(&self) -> bool {
self.0.is_exactly_zero()
}
}

#[diplomat::out]
Expand Down
25 changes: 0 additions & 25 deletions ffi/capi/tests/missing_apis.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,28 +137,3 @@ icu::datetime::options::SubsecondDigits#Enum
icu::datetime::options::SubsecondError#Enum
icu::datetime::options::TimePrecision#Enum
icu::datetime::options::YearStyle#Enum
icu::plurals::PluralElements#Struct
icu::plurals::PluralElements::as_ref#FnInStruct
icu::plurals::PluralElements::explicit_one#FnInStruct
icu::plurals::PluralElements::explicit_zero#FnInStruct
icu::plurals::PluralElements::few#FnInStruct
icu::plurals::PluralElements::many#FnInStruct
icu::plurals::PluralElements::map#FnInStruct
icu::plurals::PluralElements::new#FnInStruct
icu::plurals::PluralElements::one#FnInStruct
icu::plurals::PluralElements::other#FnInStruct
icu::plurals::PluralElements::try_into_other#FnInStruct
icu::plurals::PluralElements::two#FnInStruct
icu::plurals::PluralElements::with_explicit_one_value#FnInStruct
icu::plurals::PluralElements::with_explicit_zero_value#FnInStruct
icu::plurals::PluralElements::with_few_value#FnInStruct
icu::plurals::PluralElements::with_many_value#FnInStruct
icu::plurals::PluralElements::with_one_value#FnInStruct
icu::plurals::PluralElements::with_two_value#FnInStruct
icu::plurals::PluralElements::with_zero_value#FnInStruct
icu::plurals::PluralElements::zero#FnInStruct
icu::plurals::PluralOperands::is_exactly_one#FnInStruct
icu::plurals::PluralOperands::is_exactly_zero#FnInStruct
icu::plurals::PluralRulesOptions#Struct
icu::plurals::PluralRulesOptions::default#FnInStruct
icu::plurals::PluralRulesOptions::with_type#FnInStruct
3 changes: 3 additions & 0 deletions tools/make/diplomat-coverage/src/allowlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,9 @@ lazy_static::lazy_static! {
"icu::calendar::Date::wrap_calendar_in_arc",
"icu::calendar::Date::wrap_calendar_in_ref",

// Utility for use by other ICU4X crates
"icu::plurals::PluralElements",

// Individual markerlike calendar types and inner types
// inner types are only public for associated type reasons, and the markerlike
// calendar types exist to implement the trait
Expand Down