Skip to content

Commit

Permalink
globaldata
Browse files Browse the repository at this point in the history
  • Loading branch information
robertbastian committed May 24, 2023
1 parent b0ba025 commit 9cd2362
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 9 deletions.
8 changes: 2 additions & 6 deletions components/list/examples/and_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@ use icu::locid::locale;
fn main(_argc: isize, _argv: *const *const u8) -> isize {
icu_benchmark_macros::main_setup!();

let list_formatter = ListFormatter::try_new_and_with_length_unstable(
&icu_testdata::unstable(),
&locale!("es").into(),
ListLength::Wide,
)
.unwrap();
let list_formatter =
ListFormatter::try_new_and_with_length(&locale!("es").into(), ListLength::Wide).unwrap();

println!(
"{}",
Expand Down
33 changes: 30 additions & 3 deletions components/list/src/list_formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,37 @@ pub struct ListFormatter {
length: ListLength,
}

struct GlobalDataProvider;
mod isolate {
use crate as icu_list;
include!("../../../globaldata/mod.rs");
impl_list_and_v1!(super::GlobalDataProvider);
impl_list_or_v1!(super::GlobalDataProvider);
impl_list_unit_v1!(super::GlobalDataProvider);
}

macro_rules! constructor {
($name: ident, $name_any: ident, $name_buffer: ident, $marker: ty, $doc: literal) => {
($name: ident, $name_data: ident, $name_any: ident, $name_buffer: ident, $marker: ty, $doc: literal) => {
#[doc = concat!("Creates a new [`ListFormatter`] that produces a ", $doc, "-type list.\n\nSee the [CLDR spec]",
"(https://unicode.org/reports/tr35/tr35-general.html#ListPatterns) for an explanation of the different types.\n\n",
"[📚 Help choosing a constructor](icu_provider::constructors)\n\n")]
pub fn $name(
locale: &DataLocale,
length: ListLength,
) -> Result<Self, ListError> {
let data = DataProvider::<$marker>::load(&GlobalDataProvider, DataRequest {
locale,
metadata: Default::default(),
})?
.take_payload()?.cast();
Ok(Self { data, length })
}

#[doc = concat!("Creates a new [`ListFormatter`] that produces a ", $doc, "-type list.\n\nSee the [CLDR spec]",
"(https://unicode.org/reports/tr35/tr35-general.html#ListPatterns) for an explanation of the different types.\n\n",
"[📚 Help choosing a constructor](icu_provider::constructors)\n\n",
"<div class=\"stab unstable\">⚠️ The bounds on this function may change over time, including in SemVer minor releases.</div>")]
pub fn $name<D: DataProvider<$marker> + ?Sized>(
pub fn $name_data<D: DataProvider<$marker> + ?Sized>(
data_provider: &D,
locale: &DataLocale,
length: ListLength,
Expand All @@ -44,7 +68,7 @@ macro_rules! constructor {
style: ListLength,
error: ListError,
functions: [
Self::$name,
Self::$name_data,
$name_any,
$name_buffer
]
Expand All @@ -54,20 +78,23 @@ macro_rules! constructor {

impl ListFormatter {
constructor!(
try_new_and_with_length,
try_new_and_with_length_unstable,
try_new_and_with_length_with_any_provider,
try_new_and_with_length_with_buffer_provider,
AndListV1Marker,
"and"
);
constructor!(
try_new_or_with_length,
try_new_or_with_length_unstable,
try_new_or_with_length_with_any_provider,
try_new_or_with_length_with_buffer_provider,
OrListV1Marker,
"or"
);
constructor!(
try_new_unit_with_length,
try_new_unit_with_length_unstable,
try_new_unit_with_length_with_any_provider,
try_new_unit_with_length_with_buffer_provider,
Expand Down
Loading

0 comments on commit 9cd2362

Please sign in to comment.