Struct icu_provider_adapters::fallback::LocaleFallbacker
source · pub struct LocaleFallbacker { /* private fields */ }
Expand description
Entry type for locale fallbacking.
See the module-level documentation for an example.
Implementations§
source§impl LocaleFallbacker
impl LocaleFallbacker
sourcepub fn try_new_unstable<P>(provider: &P) -> Result<Self, DataError>where
P: DataProvider<LocaleFallbackLikelySubtagsV1Marker> + DataProvider<LocaleFallbackParentsV1Marker> + DataProvider<CollationFallbackSupplementV1Marker> + ?Sized,
pub fn try_new_unstable<P>(provider: &P) -> Result<Self, DataError>where P: DataProvider<LocaleFallbackLikelySubtagsV1Marker> + DataProvider<LocaleFallbackParentsV1Marker> + DataProvider<CollationFallbackSupplementV1Marker> + ?Sized,
Creates a LocaleFallbacker
with fallback data (likely subtags and parent locales).
⚠️ The bounds on this function may change over time, including in SemVer minor releases.
sourcepub fn try_new_with_any_provider(
provider: &impl AnyProvider + ?Sized
) -> Result<Self, DataError>
pub fn try_new_with_any_provider( provider: &impl AnyProvider + ?Sized ) -> Result<Self, DataError>
Creates a new instance using an AnyProvider
.
For details on the behavior of this function, see: Self::try_new_unstable
sourcepub fn new_without_data() -> Self
pub fn new_without_data() -> Self
Creates a LocaleFallbacker
without fallback data. Using this constructor may result in
surprising behavior, especially in multi-script languages.
sourcepub fn for_config(
&self,
config: LocaleFallbackConfig
) -> LocaleFallbackerWithConfig<'_>
pub fn for_config( &self, config: LocaleFallbackConfig ) -> LocaleFallbackerWithConfig<'_>
Creates the intermediate LocaleFallbackerWithConfig
with configuration options.
sourcepub fn for_key(&self, data_key: DataKey) -> LocaleFallbackerWithConfig<'_>
pub fn for_key(&self, data_key: DataKey) -> LocaleFallbackerWithConfig<'_>
Creates the intermediate LocaleFallbackerWithConfig
based on a
DataKey
and a DataRequestMetadata
.
Examples
use icu_locid::locale;
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(DataLocale::from(locale!("en-GB")));
// Run the algorithm and check the results.
assert_eq!(fallback_iterator.get(), &DataLocale::from(locale!("en-GB")));
fallback_iterator.step();
assert_eq!(
fallback_iterator.get(),
&DataLocale::from(locale!("und-GB"))
);
fallback_iterator.step();
assert_eq!(fallback_iterator.get(), &DataLocale::from(locale!("und")));
Trait Implementations§
source§impl Clone for LocaleFallbacker
impl Clone for LocaleFallbacker
source§fn clone(&self) -> LocaleFallbacker
fn clone(&self) -> LocaleFallbacker
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for LocaleFallbacker
impl Debug for LocaleFallbacker
source§impl PartialEq<LocaleFallbacker> for LocaleFallbacker
impl PartialEq<LocaleFallbacker> for LocaleFallbacker
source§fn eq(&self, other: &LocaleFallbacker) -> bool
fn eq(&self, other: &LocaleFallbacker) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.impl StructuralPartialEq for LocaleFallbacker
Auto Trait Implementations§
impl RefUnwindSafe for LocaleFallbacker
impl !Send for LocaleFallbacker
impl !Sync for LocaleFallbacker
impl Unpin for LocaleFallbacker
impl UnwindSafe for LocaleFallbacker
Blanket Implementations§
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