Struct icu_provider_blob::BlobDataProvider
source · 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.
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§fn clone(&self) -> BlobDataProvider
fn clone(&self) -> BlobDataProvider
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for BlobDataProvider
impl Debug for BlobDataProvider
source§impl DynamicDataProvider<BufferMarker> for BlobDataProvider
impl DynamicDataProvider<BufferMarker> for BlobDataProvider
source§impl DynamicDryDataProvider<BufferMarker> for BlobDataProvider
impl DynamicDryDataProvider<BufferMarker> for BlobDataProvider
source§impl IterableDynamicDataProvider<BufferMarker> for BlobDataProvider
impl IterableDynamicDataProvider<BufferMarker> for BlobDataProvider
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 UnwindSafe for BlobDataProvider
Blanket Implementations§
§impl<P> AsDeserializingBufferProvider for Pwhere
P: BufferProvider + ?Sized,
impl<P> AsDeserializingBufferProvider for Pwhere
P: BufferProvider + ?Sized,
§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_json
deserialize_postcard_1
deserialize_bincode_1
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more