17 releases (9 stable)

new 2.0.0-beta1 Nov 23, 2024
1.5.0 May 28, 2024
1.4.0 Nov 16, 2023
1.2.0 Apr 14, 2023
0.1.0 Oct 15, 2020

#24 in Internationalization (i18n)

Download history 102435/week @ 2024-08-03 98829/week @ 2024-08-10 93080/week @ 2024-08-17 101083/week @ 2024-08-24 100627/week @ 2024-08-31 106313/week @ 2024-09-07 105800/week @ 2024-09-14 156323/week @ 2024-09-21 153194/week @ 2024-09-28 164929/week @ 2024-10-05 151382/week @ 2024-10-12 145632/week @ 2024-10-19 131604/week @ 2024-10-26 640549/week @ 2024-11-02 873415/week @ 2024-11-09 771377/week @ 2024-11-16

2,440,085 downloads per month
Used in 27,999 crates (50 directly)

Unicode-3.0

1.5MB
21K SLoC

icu_provider crates.io

icu_provider is one of the ICU4X components.

Unicode's experience with ICU4X's parent projects, ICU4C and ICU4J, led the team to realize that data management is the most critical aspect of deploying internationalization, and that it requires a high level of customization for the needs of the platform it is embedded in. As a result ICU4X comes with a selection of providers that should allow for ICU4X to naturally fit into different business and technological needs of customers.

icu_provider defines traits and structs for transmitting data through the ICU4X locale data pipeline. The primary trait is DataProvider. It is parameterized by a DataMarker, which is the type-system-level data identifier. DataProvider has a single method, DataProvider::load, which transforms a DataRequest into a DataResponse.

  • DataRequest contains selectors to choose a specific variant of the marker, such as a locale.
  • DataResponse contains the data if the request was successful.

The most common types required for this crate are included via the prelude:

use icu_provider::prelude::*;

Dynamic Data Providers

If the type system cannot be leveraged to load data (such as when dynamically loading from I/O), there's another form of the DataProvider: DynamicDataProvider. While DataProvider is parametrized on the type-system level by a DataMarker (which are distinct types implementing this trait), DynamicDataProviders are parametrized at runtime by a DataMarkerInfo struct, which essentially is the runtime representation of the DataMarker type.

The DynamicDataProvider is still type-level parametrized by the type that it loads, and there are two implementations that should be called out

AnyProvider

These providers are able to return structured data cast into dyn Any trait objects. Users can call as_downcasting() to get an object implementing DataProvider by downcasting the trait objects.

Examples of AnyProviders:

BufferProvider

These providers are able to return unstructured data typically represented as serde-serialized buffers. Users can call as_deserializing() to get an object implementing DataProvider by invoking Serde Deserialize.

Examples of BufferProviders:

Provider Adapters

ICU4X offers several built-in modules to combine providers in interesting ways. These can be found in the icu_provider_adapters crate.

Testing Provider

This crate also contains a concrete provider for demonstration purposes:

Types and Lifetimes

Types compatible with Yokeable can be passed through the data provider, so long as they are associated with a marker type implementing DynamicDataMarker.

Data structs should generally have one lifetime argument: 'data. This lifetime allows data structs to borrow zero-copy data.

More Information

For more information on development, authorship, contributing etc. please visit ICU4X home page.

Dependencies

~0.5–1.4MB
~30K SLoC