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

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl ForkByErrorPredicate for MissingLocalePredicate

source§

const UNIT_ERROR: DataErrorKind = DataErrorKind::MissingLocale

The error to return if there are zero providers.
source§

fn test(&self, _: DataKey, _: Option<DataRequest<'_>>, err: DataError) -> bool

This function is called when a data request fails and there are additional providers that could possibly fulfill the request. Read more
source§

impl PartialEq for MissingLocalePredicate

source§

fn eq(&self, other: &MissingLocalePredicate) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for MissingLocalePredicate

source§

impl StructuralPartialEq for MissingLocalePredicate

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> Filterable for T

source§

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
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> ErasedDestructor for T
where T: 'static,

source§

impl<T> MaybeSendSync for T