Skip to content

Commit b74aafd

Browse files
Databake improvements (#2906)
1 parent 22866d3 commit b74aafd

File tree

1,310 files changed

+434760
-418398
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,310 files changed

+434760
-418398
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ ffi/diplomat/cpp/include/** linguist-generated=true
88
ffi/diplomat/cpp/docs/** linguist-generated=true
99
ffi/diplomat/js/include//** linguist-generated=true
1010
ffi/diplomat/js/docs/** linguist-generated=true
11+
*.rs.data linguist-language=Rust

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/datetime/src/provider/calendar/skeletons.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl databake::Bake for DateSkeletonPatternsV1<'_> {
8888
}
8989
});
9090
databake::quote! {
91-
[#(#vals),*]
91+
&[#(#vals),*]
9292
}
9393
}
9494
}
@@ -110,7 +110,8 @@ impl databake::Bake for DateSkeletonPatternsV1Marker {
110110
}
111111
}
112112

113-
type BakedDateSkeletonPatternsV1 = [(&'static [crate::fields::Field], PatternPlurals<'static>)];
113+
type BakedDateSkeletonPatternsV1 =
114+
&'static [(&'static [crate::fields::Field], PatternPlurals<'static>)];
114115

115116
impl zerofrom::ZeroFrom<'static, BakedDateSkeletonPatternsV1> for DateSkeletonPatternsV1<'static> {
116117
fn zero_from(other: &'static BakedDateSkeletonPatternsV1) -> Self {

docs/tutorials/data_management.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ Rebuilding the application and rerunning datagen awards us with a 3KB data blob,
133133

134134
So far we've used `--format blob` and `BlobDataProvider`. This is useful if we want to ship code and data separately, but there are other options.
135135

136-
## `mod` and `BakedDataProvider`
136+
## `mod` and baked data
137137

138-
The `mod` format will generate a Rust module that defines a data provider. This format naturally has no deserialization overhead, and allows for compile-time optimizations (data slicing isn't really necessary, as the compiler will do it for us), but cannot be dynamically loaded at runtime.
138+
The `mod` format will generate a Rust module that contains all the required data directly as Rust code. This format naturally has no deserialization overhead, and allows for compile-time optimizations (data slicing isn't really necessary, as the compiler will do it for us), but cannot be dynamically loaded at runtime.
139139

140140
Let's give it a try:
141141

@@ -154,17 +154,19 @@ $ cargo add zerovec
154154
We can then use the data by directly including the source with the `include!` macro.
155155

156156
```rust,compile_fail
157-
extern crate alloc; // required as BakedDataProvider is written for #[no_std]
157+
extern crate alloc; // required as my-data-mod is written for #[no_std]
158158
use icu::locid::{locale, Locale};
159159
use icu::calendar::DateTime;
160160
use icu::datetime::{TypedDateTimeFormatter, options::length};
161161
162162
const LOCALE: Locale = locale!("ja");
163163
164-
include!("../my-data-mod/mod.rs"); // defines BakedDataProvider
164+
struct UnstableProvider;
165+
include!("../my-data-mod/mod.rs");
166+
impl_data_provider!(UnstableProvider);
165167
166168
fn main() {
167-
let unstable_provider = BakedDataProvider;
169+
let unstable_provider = UnstableProvider;
168170
169171
let options = length::Bag::from_date_time_style(length::Date::Long, length::Time::Medium);
170172
@@ -180,14 +182,12 @@ fn main() {
180182
}
181183
```
182184

183-
With this provider, we can use the `unstable` constructors. These are only guaranteed to work if the `BakedDataProvider` was generated with the same version of ICU4X that you are building with, but if you build the data as part of your a build pipeline, that shouldn't be a problem.
185+
With this provider, we can use the `unstable` constructors. These are only guaranteed to work if the data was generated with the same version of ICU4X that you are building with, but if you build the data as part of your a build pipeline, that shouldn't be a problem.
184186

185-
You can also make the `BakedDataProvider` implement the `AnyProvider` trait, so that it can be used with `_with_any_provider` constructors. Using these constructors is slightly less performant than the `unstable` ones, but, as the name suggests, stable across (minor) releases.
187+
You can also implement the `AnyProvider` trait, so that it can be used with `_with_any_provider` constructors. Using these constructors is slightly less performant than the `unstable` ones, but, as the name suggests, stable across (minor) releases.
186188

187189
```rust,compile_fail
188-
include!("../my-data-mod/mod.rs");
189-
include!("../my-data-mod/any.rs");
190-
let _any_provider = BakedDataProvider;
190+
impl_any_provider!(MyProvider);
191191
```
192192

193193
## `dir` and `FsDataProvider`

ffi/ecma402/Cargo.lock

Lines changed: 57 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ffi/ecma402/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ impl std::fmt::Display for crate::DataLocale {
6464
}
6565
}
6666

67-
mod provider {
67+
pub(crate) struct GlobalDataProvider;
68+
69+
mod baked {
6870
include!(concat!(env!("OUT_DIR"), "/baked/mod.rs"));
71+
impl_data_provider!(super::GlobalDataProvider);
6972
}
70-
71-
pub(crate) use provider::BakedDataProvider;

ffi/ecma402/src/list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl ecma402_traits::listformat::Format for ListFormat {
2020
L: Locale,
2121
Self: Sized,
2222
{
23-
Self::try_new_with_provider(l, opts, &crate::BakedDataProvider)
23+
Self::try_new_with_provider(l, opts, &crate::GlobalDataProvider)
2424
}
2525

2626
fn format<I, L, W>(&self, list: L, writer: &mut W) -> fmt::Result

ffi/ecma402/src/pluralrules.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ impl ecma402_traits::pluralrules::PluralRules for PluralRules {
240240
L: ecma402_traits::Locale,
241241
Self: Sized,
242242
{
243-
Self::try_new_with_provider(l, opts, &crate::BakedDataProvider)
243+
Self::try_new_with_provider(l, opts, &crate::GlobalDataProvider)
244244
}
245245

246246
fn select<W>(&self, number: f64, writer: &mut W) -> std::fmt::Result

provider/datagen/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ zip = "0.6"
8484
cached-path = "0.5"
8585
reqwest = { version = "0.11", features = ["blocking"] }
8686
lazy_static = "1"
87+
rust-format = { version = "0.3.4", features = ["token_stream"] }
8788

8889
# Dependencies for "bin" feature
8990
clap = { version = "2.33", optional = true }

0 commit comments

Comments
 (0)