#[diplomat::rust_link(icu::plurals::PluralCategory, Enum)] #[diplomat::enum_convert(icu_plurals::PluralCategory)] #[non_exhaustive] pubenum PluralCategory {
Zero,
One,
Two,
Few,
Many, // This is an output type, so the default mostly impacts deferred initialization. #[diplomat::attr(auto, default)]
Other,
}
impl PluralCategory { /// Construct from a string in the format /// [specified in TR35](https://unicode.org/reports/tr35/tr35-numbers.html#Language_Plural_Rules) #[diplomat::rust_link(icu::plurals::PluralCategory::get_for_cldr_string, FnInEnum)] #[diplomat::rust_link(icu::plurals::PluralCategory::get_for_cldr_bytes, FnInEnum)] pubfn get_for_cldr_string(s: &DiplomatStr) -> Option<PluralCategory> {
icu_plurals::PluralCategory::get_for_cldr_bytes(s).map(Into::into)
}
}
impl PluralRules { /// Construct an [`PluralRules`] for the given locale, for cardinal numbers, using compiled data. #[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")] #[diplomat::demo(default_constructor)] pubfn create_cardinal(locale: &Locale) -> Result<Box<PluralRules>, DataError> { let prefs = icu_plurals::PluralRulesPreferences::from(&locale.0);
Ok(Box::new(PluralRules(
icu_plurals::PluralRules::try_new_cardinal(prefs)?,
)))
} /// Construct an [`PluralRules`] for the given locale, for cardinal numbers, using a particular data source. #[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::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "cardinal_with_provider")] #[cfg(feature = "buffer_provider")] pubfn create_cardinal_with_provider(
provider: &DataProvider,
locale: &Locale,
) -> Result<Box<PluralRules>, DataError> { let prefs = icu_plurals::PluralRulesPreferences::from(&locale.0);
Ok(Box::new(PluralRules(
icu_plurals::PluralRules::try_new_cardinal_with_buffer_provider(
provider.get()?,
prefs,
)?,
)))
} /// Construct an [`PluralRules`] for the given locale, for ordinal numbers, using compiled data. #[diplomat::rust_link(icu::plurals::PluralRules::try_new_ordinal, FnInStruct)] #[diplomat::rust_link(icu::plurals::PluralRules::try_new, FnInStruct, hidden)] #[diplomat::rust_link(icu::plurals::PluralRuleType, Enum, hidden)] #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "ordinal")] #[cfg(feature = "compiled_data")] pubfn create_ordinal(locale: &Locale) -> Result<Box<PluralRules>, DataError> { let prefs = icu_plurals::PluralRulesPreferences::from(&locale.0);
Ok(Box::new(PluralRules(
icu_plurals::PluralRules::try_new_ordinal(prefs)?,
)))
} /// Construct an [`PluralRules`] for the given locale, for ordinal numbers, using a particular data source. #[diplomat::rust_link(icu::plurals::PluralRules::try_new_ordinal, FnInStruct)] #[diplomat::rust_link(icu::plurals::PluralRules::try_new, FnInStruct, hidden)] #[diplomat::rust_link(icu::plurals::PluralRuleType, Enum, hidden)] #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "ordinal_with_provider")] #[cfg(feature = "buffer_provider")] pubfn create_ordinal_with_provider(
provider: &DataProvider,
locale: &Locale,
) -> Result<Box<PluralRules>, DataError> { let prefs = icu_plurals::PluralRulesPreferences::from(&locale.0);
Ok(Box::new(PluralRules(
icu_plurals::PluralRules::try_new_ordinal_with_buffer_provider(
provider.get()?,
prefs,
)?,
)))
} /// Get the category for a given number represented as operands #[diplomat::rust_link(icu::plurals::PluralRules::category_for, FnInStruct)] pubfn category_for(&self, op: &PluralOperands) -> PluralCategory { self.0.category_for(op.0).into()
}
/// Get all of the categories needed in the current locale #[diplomat::rust_link(icu::plurals::PluralRules::categories, FnInStruct)] #[diplomat::attr(auto, getter)] pubfn categories(&self) -> PluralCategories {
PluralCategories::from_iter(self.0.categories())
}
}
impl PluralOperands { /// Construct for a given string representing a number #[diplomat::rust_link(icu::plurals::PluralOperands::from_str, FnInStruct)] #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor)] pubfn from_string(s: &DiplomatStr) -> Result<Box<PluralOperands>, DecimalParseError> {
Ok(Box::new(PluralOperands(icu_plurals::PluralOperands::from(
&fixed_decimal::Decimal::try_from_utf8(s)?,
))))
}
/// Construct for a given integer #[diplomat::attr(auto, named_constructor)] #[diplomat::attr(dart, rename = "from_int")] #[diplomat::attr(js, rename = "from_big_int")] #[diplomat::attr(supports = method_overloading, rename = "from")] pubfn from_int64(i: i64) -> Box<PluralOperands> { Box::new(PluralOperands(icu_plurals::PluralOperands::from(i)))
}
/// Construct from a FixedDecimal /// /// Retains at most 18 digits each from the integer and fraction parts. #[cfg(feature = "decimal")] #[diplomat::attr(auto, named_constructor)] #[diplomat::demo(default_constructor)] pubfn from_fixed_decimal(x: &crate::unstable::fixed_decimal::ffi::Decimal) -> Box<Self> { Box::new(Self((&x.0).into()))
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.