pub struct BlobDataProvider { /* private fields */ }
Expand description

A data provider loading data from blobs dynamically created at runtime.

This enables data blobs to be read from the filesystem or from an HTTP request dynamically at runtime, so that the code and data can be shipped separately.

If you prefer to bake the data into your binary, see StaticDataProvider.

Examples

use icu_locid::locale;
use icu_provider::prelude::*;
use icu_provider::hello_world::*;
use icu_provider_blob::BlobDataProvider;
use std::fs;

// Read an ICU4X data blob dynamically:
let blob = fs::read(concat!(
    env!("CARGO_MANIFEST_DIR"),
    "/tests/data/hello_world.postcard",
)).expect("Reading pre-computed postcard buffer");

// Create a DataProvider from it:
let provider = BlobDataProvider::new_from_rc_blob(blob.into())
    .expect("Deserialization should succeed");

// Check that it works:
let response: DataPayload<HelloWorldV1Marker> = provider
    .load_resource(&DataRequest {
        options: locale!("la").into(),
        metadata: Default::default(),
    })
    .expect("Data should be valid")
    .take_payload()
    .expect("Data should be present");

assert_eq!(response.get().message, "Ave, munde");

Implementations

Create a BlobDataProvider from an Rc blob of ICU4X data.

Trait Implementations

Query the provider for data, returning the result. Read more

Query the provider for data, returning the result. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.