pub struct LocaleFallbacker { /* private fields */ }
Expand description

Entry type for locale fallbacking.

See the module-level documentation for an example.

Implementations

Creates a LocaleFallbacker with fallback data (likely subtags and parent locales).

📚 Help choosing a constructor

⚠️ The bounds on this function may change over time, including in SemVer minor releases.

Creates a new instance using an AnyProvider.

For details on the behavior of this function, see: Self::try_new_unstable

📚 Help choosing a constructor

Creates a LocaleFallbacker without fallback data. Using this constructor may result in surprising behavior, especially in multi-script languages.

Creates the intermediate LocaleFallbackerWithConfig with configuration options.

Creates the intermediate LocaleFallbackerWithConfig based on a DataKey and a DataRequestMetadata.

Examples
use icu_provider::prelude::*;
use icu_provider_adapters::fallback::LocaleFallbacker;
use std::borrow::Cow;

// Define the data struct with key.
#[icu_provider::data_struct(marker(
    FooV1Marker,
    "demo/foo@1",
    fallback_by = "region"
))]
pub struct FooV1<'data> {
    message: Cow<'data, str>,
};

// Set up the fallback iterator.
let fallbacker =
    LocaleFallbacker::try_new_unstable(&icu_testdata::unstable())
        .expect("data");
let key_fallbacker = fallbacker.for_key(FooV1Marker::KEY);
let mut fallback_iterator =
    key_fallbacker.fallback_for(icu_locid::locale!("en-GB").into());

// Run the algorithm and check the results.
assert_eq!(fallback_iterator.get().to_string(), "en-GB");
fallback_iterator.step();
assert_eq!(fallback_iterator.get().to_string(), "und-GB");
fallback_iterator.step();
assert_eq!(fallback_iterator.get().to_string(), "und");

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Creates a filterable data provider with the given name for debugging. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.