pub struct BlobDataProvider { /* private fields */ }Expand description
A data provider that reads from serialized blobs of data.
This enables data blobs to be read from arbitrary sources at runtime, allowing code and data to be separated. Alternatively, blobs can also be statically included at compile time.
BlobDataProvider implements BufferProvider, so it can be used in
*_with_buffer_provider constructors across ICU4X.
§Sync + Send
This provider uses reference counting internally. When the sync Cargo feature on the icu_provider
crate is enabled, it uses Arc instead of Rc, making
it Sync + Send.
§Examples
§Dynamic loading
Load “hello world” data from a postcard blob loaded at runtime:
use icu_locale_core::locale;
use icu_provider::hello_world::HelloWorldFormatter;
use icu_provider_blob::BlobDataProvider;
use writeable::assert_writeable_eq;
// Read an ICU4X data blob dynamically:
let blob = std::fs::read("tests/data/v3.postcard")
.expect("Reading pre-computed postcard buffer");
// Create a DataProvider from it:
let provider = BlobDataProvider::try_new_from_blob(blob.into_boxed_slice())
.expect("Deserialization should succeed");
// Check that it works:
let formatter = HelloWorldFormatter::try_new_with_buffer_provider(
&provider,
locale!("la").into(),
)
.expect("locale exists");
assert_writeable_eq!(formatter.format(), "Ave, munde");§Static loading
Load “hello world” data from a postcard blob statically linked at compile time:
use icu_locale_core::locale;
use icu_provider::hello_world::HelloWorldFormatter;
use icu_provider_blob::BlobDataProvider;
use writeable::assert_writeable_eq;
// Read an ICU4X data blob statically:
const HELLO_WORLD_BLOB: &[u8] = include_bytes!("../tests/data/v3.postcard");
// Create a DataProvider from it:
let provider = BlobDataProvider::try_new_from_static_blob(HELLO_WORLD_BLOB)
.expect("Deserialization should succeed");
// Check that it works:
let formatter = HelloWorldFormatter::try_new_with_buffer_provider(
&provider,
locale!("la").into(),
)
.expect("locale exists");
assert_writeable_eq!(formatter.format(), "Ave, munde");Implementations§
Source§impl BlobDataProvider
impl BlobDataProvider
Sourcepub fn try_new_from_blob(blob: Box<[u8]>) -> Result<Self, DataError>
pub fn try_new_from_blob(blob: Box<[u8]>) -> Result<Self, DataError>
Create a BlobDataProvider from a blob of ICU4X data.
✨ Enabled with the alloc Cargo feature.
Sourcepub fn try_new_from_static_blob(blob: &'static [u8]) -> Result<Self, DataError>
pub fn try_new_from_static_blob(blob: &'static [u8]) -> Result<Self, DataError>
Create a BlobDataProvider from a static blob. This is a special case of
try_new_from_blob and is allocation-free.
Trait Implementations§
Source§impl Clone for BlobDataProvider
impl Clone for BlobDataProvider
Source§impl Debug for BlobDataProvider
impl Debug for BlobDataProvider
Source§impl DynamicDataProvider<BufferMarker> for BlobDataProvider
impl DynamicDataProvider<BufferMarker> for BlobDataProvider
Source§fn load_data(
&self,
marker: DataMarkerInfo,
req: DataRequest<'_>,
) -> Result<DataResponse<BufferMarker>, DataError>
fn load_data( &self, marker: DataMarkerInfo, req: DataRequest<'_>, ) -> Result<DataResponse<BufferMarker>, DataError>
Source§impl DynamicDryDataProvider<BufferMarker> for BlobDataProvider
impl DynamicDryDataProvider<BufferMarker> for BlobDataProvider
Source§fn dry_load_data(
&self,
marker: DataMarkerInfo,
req: DataRequest<'_>,
) -> Result<DataResponseMetadata, DataError>
fn dry_load_data( &self, marker: DataMarkerInfo, req: DataRequest<'_>, ) -> Result<DataResponseMetadata, DataError>
Source§impl IterableDynamicDataProvider<BufferMarker> for BlobDataProvider
Available on crate feature alloc only.✨ Enabled with the alloc Cargo feature.
impl IterableDynamicDataProvider<BufferMarker> for BlobDataProvider
alloc only.✨ Enabled with the alloc Cargo feature.
Source§fn iter_ids_for_marker(
&self,
marker: DataMarkerInfo,
) -> Result<BTreeSet<DataIdentifierCow<'_>>, DataError>
fn iter_ids_for_marker( &self, marker: DataMarkerInfo, ) -> Result<BTreeSet<DataIdentifierCow<'_>>, DataError>
DataMarkerInfo, returns a set of DataIdentifierCow.Auto Trait Implementations§
impl Freeze for BlobDataProvider
impl RefUnwindSafe for BlobDataProvider
impl Send for BlobDataProvider
impl Sync for BlobDataProvider
impl Unpin for BlobDataProvider
impl UnsafeUnpin for BlobDataProvider
impl UnwindSafe for BlobDataProvider
Blanket Implementations§
Source§impl<P> AsDeserializingBufferProvider for Pwhere
P: BufferProvider + ?Sized,
impl<P> AsDeserializingBufferProvider for Pwhere
P: BufferProvider + ?Sized,
Source§fn as_deserializing(&self) -> DeserializingBufferProvider<'_, P>
fn as_deserializing(&self) -> DeserializingBufferProvider<'_, P>
Wrap this BufferProvider in a DeserializingBufferProvider.
This requires enabling the deserialization Cargo feature for the expected format(s):
deserialize_jsondeserialize_postcard_1deserialize_bincode_1
✨ Enabled with the serde Cargo feature.