pub struct MissingLocalePredicate;
Expand description
A predicate that allows forking providers to search for a provider that supports a
particular locale, based on whether it returns DataErrorKind::MissingLocale
.
§Examples
Configure a multi-language data provider pointing at two language packs:
use icu_provider_adapters::fork::ForkByErrorProvider;
use icu_provider_adapters::fork::predicates::MissingLocalePredicate;
use icu_provider_fs::FsDataProvider;
use icu_provider::prelude::*;
use icu_provider::hello_world::HelloWorldV1Marker;
use icu_locid::langid;
// The `tests` directory contains two separate "language packs" for Hello World data.
let provider_de = FsDataProvider::try_new("tests/data/langtest/de").unwrap();
let provider_ro = FsDataProvider::try_new("tests/data/langtest/ro").unwrap();
// Create the forking provider:
let provider = ForkByErrorProvider::new_with_predicate(
provider_de,
provider_ro,
MissingLocalePredicate
);
// Test that we can load both "de" and "ro" data:
let german_hello_world: DataPayload<HelloWorldV1Marker> = provider
.as_deserializing()
.load(DataRequest {
locale: &langid!("de").into(),
metadata: Default::default(),
})
.expect("Loading should succeed")
.take_payload()
.expect("Data should be present");
assert_eq!("Hallo Welt", german_hello_world.get().message);
let romanian_hello_world: DataPayload<HelloWorldV1Marker> = provider
.as_deserializing()
.load(DataRequest {
locale: &langid!("ro").into(),
metadata: Default::default(),
})
.expect("Loading should succeed")
.take_payload()
.expect("Data should be present");
assert_eq!("Salut, lume", romanian_hello_world.get().message);
// We should not be able to load "en" data because it is not in the provider:
DataProvider::<HelloWorldV1Marker>::load(
&provider.as_deserializing(),
DataRequest {
locale: &langid!("en").into(),
metadata: Default::default(),
}
)
.expect_err("No English data");
Trait Implementations§
source§impl Debug for MissingLocalePredicate
impl Debug for MissingLocalePredicate
source§impl ForkByErrorPredicate for MissingLocalePredicate
impl ForkByErrorPredicate for MissingLocalePredicate
source§const UNIT_ERROR: DataErrorKind = DataErrorKind::MissingLocale
const UNIT_ERROR: DataErrorKind = DataErrorKind::MissingLocale
The error to return if there are zero providers.
source§impl PartialEq for MissingLocalePredicate
impl PartialEq for MissingLocalePredicate
source§fn eq(&self, other: &MissingLocalePredicate) -> bool
fn eq(&self, other: &MissingLocalePredicate) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.impl Eq for MissingLocalePredicate
impl StructuralPartialEq for MissingLocalePredicate
Auto Trait Implementations§
impl Freeze for MissingLocalePredicate
impl RefUnwindSafe for MissingLocalePredicate
impl Send for MissingLocalePredicate
impl Sync for MissingLocalePredicate
impl Unpin for MissingLocalePredicate
impl UnwindSafe for MissingLocalePredicate
Blanket Implementations§
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
Mutably borrows from an owned value. Read more
source§impl<T> Filterable for T
impl<T> Filterable for T
source§fn filterable(
self,
filter_name: &'static str,
) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>
fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>
Creates a filterable data provider with the given name for debugging. Read more