Expand description

icu_provider is one of the ICU4X components.

It defines traits and structs for transmitting data through the ICU4X locale data pipeline. The primary trait is DataProvider. It has one method, which transforms a Request into a Response:

fn load_payload(&self, req: &DataRequest) -> Result<DataResponse<'data>, DataError>

A Request contains a ResourceKey (a fixed identifier such as “plurals/cardinal@1”) and ResourceOptions (a language identifier and optional variant, e.g. “fr”) being requested. The Response contains the data payload corresponding to the Request.

A Response contains a DataPayload along with other metadata.

The most common types required for ICU4X DataProvider are included via the prelude:

use icu_provider::prelude::*;

Concrete Implementations of Data Providers

Any object implementing DataProvider can be used to supply ICU4X with locale data. ICU4X ships with some pre-built data providers:

  • CldrJsonDataProvider reads structured data directly from CLDR source files.
  • FsDataProvider reads structured data from the filesystem. It can also write out that filesystem structure. More efficient than CldrJsonDataProvider.

This crate also contains some concrete implementations for testing 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 DataMarker.

Most DataProvider traits take one lifetime argument: 'data. This lifetime allows data structs to borrow zero-copy data. In practice, it also represents the lifetime of data that the Cart of the Yoke of the DataPayload borrows; for more information on carts and yokes, see yoke.

Additional Traits

IterableDataProvider

Data providers can implement IterableProvider, allowing iteration over all ResourceOptions instances supported for a certain key in the data provider.

For more information, see the iter module.

BufferProvider

The trait BufferProvider represents a data provider that produces buffers ([u8]), which are typically deserialized later via Serde. This allows for a Serde-enabled provider to be saved as a trait object without being specific to a data struct type.

AnyProvider

The trait AnyProvider removes the type argument from DataProvider and requires that all data structs be convertible to the Any type. This enables the processing of data without the caller knowing the underlying data struct.

Since AnyProvider is not specific to a single type, it can be useful for caches or other bulk data operations.

DataProvider<SerializeMarker>

Enabled with the “serialize” feature

Data providers capable of returning opaque erased_serde::Serialize trait objects can be used as input to a data exporter, such as when writing data to the filesystem.

This trait is normally implemented using the impl_dyn_provider! macro.

This trait is normally implemented using the impl_dyn_provider! macro.

Re-exports

pub use yoke;
pub use prelude::*;

Modules

Traits for data providers that produce Any objects.

Traits for data providers that produce opaque buffers.

Utilities for using trait objects with DataPayload.

Helpers for switching between multiple providers.

Types having to do with the exporting of data.

Providers that filter resource requests.

Providers that combine multiple other providers.

Data provider returning multilingual “Hello World” strings for testing.

Locale-invariant data provider that requires no I/O.

Collection of iteration APIs for DataProvider.

Marker types and traits for DataProvider.

Core selection of APIs and structures for DataProvider.

Collection of traits for providers that support serializing or deserializing data.

Data provider always serving the same struct.

Macros

Implements DataProvider for a marker type S on a type that already implements DataProvider for one or more M, where M is a concrete type that is convertible to S via UpcastDataPayload.

Attribute Macros

The #[data_struct] attribute should be applied to all types intended for use in a DataStruct. It does the following things: