Module icu_provider_export::baked_exporter
Expand description
A data exporter that bakes the data into Rust code.
This module can be used as a target for the icu_provider_export
crate.
See our datagen tutorial for more information about different data providers.
§Examples
use icu_provider_export::baked_exporter::*;
use icu_provider_export::prelude::*;
let demo_path = std::env::temp_dir().join("icu4x_baked_demo");
// Set up the exporter
let mut exporter =
BakedExporter::new(demo_path.clone(), Default::default()).unwrap();
// Export something. Make sure to use the same fallback data at runtime!
ExportDriver::new(
[DataLocaleFamily::FULL],
DeduplicationStrategy::Maximal.into(),
LocaleFallbacker::new().static_to_owned(),
)
.export(&icu_provider::hello_world::HelloWorldProvider, exporter)
.unwrap();
There are two ways to use baked data: you can build custom data providers for use with
_unstable
constructors, or you can use it with the
compiled_data
Cargo feature and constructors.
§Custom DataProvider
This allows you to use baked data in custom data pipelines, such as including some baked data and lazily loading more data from the network.
use icu_locale_core::locale;
use icu_provider::hello_world::*;
include!("/tmp/icu4x_baked_demo/mod.rs");
pub struct MyDataProvider;
impl_data_provider!(MyDataProvider);
let formatter = HelloWorldFormatter::try_new_unstable(&MyDataProvider, locale!("en").into()).unwrap();
assert_eq!(formatter.format_to_string(), "Hello World");
§compiled_data
You can use baked data to overwrite the compiled data that’s included in ICU4X.
To do this, build your binary with the ICU4X_DATA_DIR
environment variable:
ICU4X_DATA_DIR=/tmp/icu4x_baked_demo cargo build <...>
use icu_locale_core::locale;
use icu_provider::hello_world::*;
let formatter = HelloWorldFormatter::try_new(locale!("en").into()).unwrap();
assert_eq!(formatter.format_to_string(), "Hello World");
Structs§
- See the module-level documentation for details.
- Options for configuring the output of
BakedExporter
.