Skip to content

Commit

Permalink
globaldata
Browse files Browse the repository at this point in the history
  • Loading branch information
robertbastian committed May 30, 2023
1 parent 1baf9e9 commit 103e727
Show file tree
Hide file tree
Showing 1,350 changed files with 363 additions and 94,424 deletions.
9 changes: 9 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ members = [
"provider/core",
"provider/datagen",
"provider/fs",
"provider/globaldata",
"provider/macros",
"provider/repodata",
"provider/testdata",
Expand Down
4 changes: 4 additions & 0 deletions components/list/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ icu_provider = { version = "1.2.0", path = "../../provider/core", features = ["m
regex-automata = { version = "0.2", default-features = false }
writeable = { version = "0.5.1", path = "../../utils/writeable" }

icu_globaldata = { version = "1.2.0", path = "../../provider/globaldata", optional = true }
icu_locid = { version = "1.2.0", path = "../locid", optional = true }

databake = { version = "0.1.3", path = "../../utils/databake", optional = true, features = ["derive"]}
deduplicating_array = { version = "0.1.3", path = "../../utils/deduplicating_array", optional = true }
serde = { version = "1.0", default-features = false, features = ["derive", "alloc"], optional = true }
Expand All @@ -51,6 +54,7 @@ serde = ["dep:deduplicating_array", "dep:serde", "icu_provider/serde"]
serde_human = ["serde", "regex-automata/alloc"]
datagen = ["serde", "std", "dep:databake", "regex-automata/alloc"]
bench = []
globaldata = ["dep:icu_globaldata", "dep:icu_locid"]

[package.metadata.cargo-all-features]
# Bench feature gets tested separately and is only relevant for CI
Expand Down
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
35 changes: 32 additions & 3 deletions components/list/src/list_formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,39 @@ pub struct ListFormatter {
length: ListLength,
}

#[cfg(feature = "globaldata")]
struct GlobalDataProvider;
#[cfg(feature = "globaldata")]
mod isolate {
use crate as icu_list;
icu_globaldata::impl_list_and_v1!(super::GlobalDataProvider);
icu_globaldata::impl_list_or_v1!(super::GlobalDataProvider);
icu_globaldata::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")]
#[cfg(feature = "globaldata")]
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 +70,7 @@ macro_rules! constructor {
style: ListLength,
error: ListError,
functions: [
Self::$name,
Self::$name_data,
$name_any,
$name_buffer
]
Expand All @@ -54,20 +80,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 103e727

Please sign in to comment.