-
Notifications
You must be signed in to change notification settings - Fork 161
/
mod.rs
62 lines (58 loc) · 1.99 KB
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// This file is part of ICU4X. For terms of use, please see the file
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
//! Data exporter that creates a binary blob for use with [`BlobDataProvider`](crate::BlobDataProvider).
//!
//! This module can be used as a target for the `icu_datagen` crate.
//!
//! See our [datagen tutorial](https://github.com/unicode-org/icu4x/blob/main/tutorials/data_management.md) for more information about different data providers.
//!
//! # Examples
//!
//! ```
//! use icu_datagen::prelude::*;
//! use icu_provider_blob::export::*;
//!
//! let mut blob: Vec<u8> = Vec::new();
//!
//! // Set up the exporter
//! let mut exporter = BlobExporter::new_v2_with_sink(Box::new(&mut blob));
//!
//! // Export something
//! DatagenDriver::new()
//! .with_keys([icu_provider::hello_world::HelloWorldV1Marker::KEY])
//! .with_all_locales()
//! .export(&icu_provider::hello_world::HelloWorldProvider, exporter)
//! .unwrap();
//!
//! // communicate the blob to the client application (network, disk, etc.)
//! # assert_eq!(blob, include_bytes!("../../tests/data/v2.postcard"));
//! ```
//!
//! The resulting blob can now be used like this:
//!
//! ```
//! use icu_locid::langid;
//! use icu_provider::hello_world::*;
//! use icu_provider::prelude::*;
//! use icu_provider_blob::BlobDataProvider;
//!
//! // obtain the data blob
//! # let blob = include_bytes!("../../tests/data/v2.postcard").to_vec();
//!
//! // Create a provider reading from the blob
//! let provider = BlobDataProvider::try_new_from_blob(blob.into_boxed_slice())
//! .expect("Should successfully read from blob");
//!
//! // 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");
//! ```
mod blob_exporter;
mod iter;
pub use blob_exporter::BlobExporter;