Module icu_provider_fs::export
source · Expand description
Data exporter that creates a file system structure for use with FsDataProvider
.
This module can be used as a target for the icu_datagen
crate.
See our datagen tutorial for more information about different data providers.
Examples
use icu_datagen::prelude::*;
use icu_provider_fs::export::*;
let demo_path = std::env::temp_dir().join("icu4x_json_demo");
// Set up the exporter
let mut options = ExporterOptions::default();
options.root = demo_path.clone();
let serializer = Box::new(serializers::Json::default());
let mut exporter = FilesystemExporter::try_new(serializer, options)
.expect("Should successfully initialize data output directory");
// Export something
DatagenDriver::new()
.with_keys([icu_provider::hello_world::HelloWorldV1Marker::KEY])
.with_all_locales()
.export(&DatagenProvider::new_latest_tested(), exporter)
.unwrap();
The resulting files can now be used like this:
use icu_locid::langid;
use icu_provider::hello_world::*;
use icu_provider::prelude::*;
use icu_provider_fs::FsDataProvider;
// Create a filesystem provider reading from the demo directory
let provider = FsDataProvider::try_new(&demo_path)
.expect("Should successfully read from filesystem");
// Use the provider as a `BufferProvider`
let formatter = HelloWorldFormatter::try_new_with_buffer_provider(
&provider,
&langid!("en").into(),
)
.unwrap();
assert_eq!(formatter.format_to_string(), "Hello World");
Modules
- Serializer configurations for the
FilesystemExporter
.
Structs
- A data exporter that writes data to a filesystem hierarchy. See the module-level docs for an example.
- Options bag for initializing a
FilesystemExporter
.
Enums
- Choices of what to do if
FilesystemExporter
tries to write to a pre-existing directory.