pub trait BufferProvider {
    fn load_buffer(
        key: DataKey,
        req: DataRequest<'_>
    ) -> Result<DataResponse<BufferMarker>, DataError>; }
Expand description

A data provider that returns opaque bytes.

Generally, these bytes are expected to be deserializable with Serde. To get an object implementing DataProvider via Serde, use as_deserializing(), which requires enabling at least one of the deserialization Cargo features:

  • deserialize_json
  • deserialize_postcard_1
  • deserialize_bincode_1

Along with DataProvider, this is one of the two foundational traits in this crate.

BufferProvider can be made into a trait object. It is used over FFI.


use icu_locid::locale;
use icu_provider::hello_world::*;
use icu_provider::prelude::*;

let buffer_provider = HelloWorldProvider.into_json_provider();

let data_provider = buffer_provider.as_deserializing();

let german_hello_world: DataPayload<HelloWorldV1Marker> = data_provider
    .load(DataRequest {
        locale: &locale!("de").into(),
        metadata: Default::default(),
    .expect("Loading should succeed")
    .expect("Data should be present");

assert_eq!("Hallo Welt", german_hello_world.get().message);

Required methods

Loads a DataPayload<BufferMarker> according to the key and request.

Implementations on Foreign Types