icu 
icu
is the main meta-crate of the ICU4X
project.
It provides a comprehensive selection of functionality found in International Components for Unicode in their canonical configurations intended to enable software internationalization capabilities.
This crate exists to collect the most important functionality for users
together in one place.
It does not bring any unique functionality, but rather,
it re-exports the relevant crates as modules.
The exported crate corresponding to each module is also
available in a stand-alone manner, i.e. icu::list
as icu_list
.
Data Management
Most functionality relies on data which clients have to provide to the APIs.
ICU4X
uses the concept of a DataProvider
to separate data from logic.
Data providers come in many different forms; the following providers are provided
by ICU4X
in separate crates:
BlobDataProvider
: uses an in-memory serde-serialized blob. This is the most flexible provider, and data can be updated at runtime.BakedDataProvider
: a code-generated provider that contains the data directly in Rust code. This is the most efficient provider as it's serialization-free, and allows for compile-time optimizations.FsDataProvider
: uses a file system tree of Serde files. This is mostly useful for development and not recommended in production for performance reasons.icu_provider_adapters
: this crate contains APIs to combine providers or provide additional functionality such as locale fallback.
The data that is required by these providers (in BakedDataProvider
's case, the provider itself) can be
generated and customized using the icu_datagen
crate.
The following example uses the icu_testdata
crate, which contains prepackaged data providers
for a small set of locales.
Example
use DateTime;
use ;
use locale;
use assert_writeable_eq;
let options = from_date_time_style
.into;
let dtf = try_new_unstable
.expect;
let date = try_new_iso_datetime
.expect;
let date = date.to_any;
let formatted_date = dtf.format.expect;
assert_writeable_eq!;
let formatted_date_string =
dtf.format_to_string.expect;
assert_eq!;
Features
ICU4X components share a set of common Cargo features that control whether core pieces of functionality are compiled. These features are:
std
: Whether to includestd
support. Without this Cargo feature,icu
is#[no_std]
-compatibleserde
: Whether to includeserde::Deserialize
implementations for data structs, such asSymbolsV1
, andserde::{Serialize, Deserialize}
implementations for core library types, such asLocale
. These are required withserde
-backed providers like [BlobDataProvider
][^1].experimental
: Whether to enable experimental preview features. Modules enabled with this feature may not be production-ready and could change at any time.
The following Cargo features are only available on the individual crates, but not on this meta-crate:
datagen
: Whether to implementserde::Serialize
and functionality that is only required during data generation.bench
: Whether to enable exhaustive benchmarks. This can be enabled on individual crates when runningcargo bench
.
There are additional features that, when enabled on specific crates, enable functionality across ICU4X:
icu_provider/sync
: makesDataPayload
implementSend + Sync
, which in turn makes most ICU4X objects also implementSend + Sync
.icu_provider/deserialize_*
: enables ICU4X buffer providers to read various different serialization formats. SeeBufferProvider
for details.
[^1]: If using blob data, you need to enable one of the deserialization Cargo features on the icu_provider
crate, as noted above.
More Information
For more information on development, authorship, contributing etc. please visit ICU4X home page
.