Module icu_decimal::provider
source · Expand description
🚧 [Unstable] Data provider struct definitions for this ICU4X component.
🚧 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.
Read more about data providers: [icu_provider
]
§Examples
§Get the resolved numbering system
In a constructor call, the last request for DecimalDigitsV1Marker
contains the resolved numbering system as its attribute:
use icu_provider::prelude::*;
use icu::decimal::FixedDecimalFormatter;
use icu::decimal::provider::DecimalDigitsV1Marker;
use icu::locale::locale;
use std::any::TypeId;
use std::cell::RefCell;
struct NumberingSystemInspectionProvider<P> {
inner: P,
numbering_system: RefCell<Option<Box<DataMarkerAttributes>>>,
}
impl<M, P> DataProvider<M> for NumberingSystemInspectionProvider<P>
where
M: DataMarker,
P: DataProvider<M>,
{
fn load(&self, req: DataRequest) -> Result<DataResponse<M>, DataError> {
if TypeId::of::<M>() == TypeId::of::<DecimalDigitsV1Marker>() {
*self.numbering_system.try_borrow_mut().unwrap() = Some(req.id.marker_attributes.to_owned());
}
self.inner.load(req)
}
}
let provider = NumberingSystemInspectionProvider {
inner: icu::decimal::provider::Baked,
numbering_system: RefCell::new(None),
};
let fdf = FixedDecimalFormatter::try_new_unstable(
&provider,
locale!("th").into(),
Default::default(),
)
.unwrap();
assert_eq!(provider.numbering_system.borrow().as_ref().map(|x| x.as_str()), Some("latn"));
let fdf = FixedDecimalFormatter::try_new_unstable(
&provider,
locale!("th-u-nu-thai").into(),
Default::default(),
)
.unwrap();
assert_eq!(provider.numbering_system.borrow().as_ref().map(|x| x.as_str()), Some("thai"));
let fdf = FixedDecimalFormatter::try_new_unstable(
&provider,
locale!("th-u-nu-adlm").into(),
Default::default(),
)
.unwrap();
assert_eq!(provider.numbering_system.borrow().as_ref().map(|x| x.as_str()), Some("adlm"));
Structs§
- Baked data
- The digits for a given numbering system. This data ought to be stored in the
und
locale with an auxiliary key set to the numbering system code. - Marker type for
DecimalDigitsV1
: “decimal/digits@1” - A stack representation of the strings used in
DecimalSymbolsV2
, i.e. a builder type forDecimalSymbolsStrs
. This type can be obtained from aDecimalSymbolsStrs
theFrom
/Into
traits. - Symbols and metadata required for formatting a
SignedFixedDecimal
. - Marker type for
DecimalSymbolsV2
: “decimal/symbols@2” - A collection of settings expressing where to put grouping separators in a decimal number. For example,
1,000,000
has two grouping separators, positioned along every 3 digits.
Constants§
- The latest minimum set of markers required by this component.