Type Alias icu_provider_adapters::fork::MultiForkByKeyProvider
source · pub type MultiForkByKeyProvider<P> = MultiForkByErrorProvider<P, MissingDataKeyPredicate>;
Expand description
A provider that returns data from the first child provider supporting the key.
The result of the first provider that supports a particular DataKey
will be returned,
even if the request failed for other reasons (such as an unsupported language). Therefore,
you should add child providers that support disjoint sets of keys.
MultiForkByKeyProvider
does not support forking between DataProvider
s. However, it
supports forking between AnyProvider
, BufferProvider
, and DynamicDataProvider
.
§Examples
use icu_locid::{subtags::language, langid};
use icu_provider::hello_world::*;
use icu_provider::prelude::*;
use icu_provider_adapters::filter::Filterable;
use icu_provider_adapters::fork::MultiForkByKeyProvider;
let forking_provider = MultiForkByKeyProvider::new(
vec![
HelloWorldProvider
.into_json_provider()
.filterable("Chinese")
.filter_by_langid(|langid| langid.language == language!("zh")),
HelloWorldProvider
.into_json_provider()
.filterable("German")
.filter_by_langid(|langid| langid.language == language!("de")),
],
);
let provider: &dyn DataProvider<HelloWorldV1Marker> =
&forking_provider.as_deserializing();
// Chinese is the first provider, so this succeeds
let chinese_hello_world = provider
.load(DataRequest {
locale: &langid!("zh").into(),
metadata: Default::default(),
})
.expect("Loading should succeed")
.take_payload()
.expect("Data should be present");
assert_eq!("你好世界", chinese_hello_world.get().message);
// German is shadowed by Chinese, so this fails
provider
.load(DataRequest {
locale: &langid!("de").into(),
metadata: Default::default(),
})
.expect_err("Should stop at the first provider, even though the second has data");
Aliased Type§
struct MultiForkByKeyProvider<P> {
providers: Vec<P>,
predicate: MissingDataKeyPredicate,
}
Fields§
§providers: Vec<P>
§predicate: MissingDataKeyPredicate