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
sourceimpl 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_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
sourceimpl Clone for LocaleFallbacker
impl Clone for LocaleFallbacker
sourcefn clone(&self) -> LocaleFallbacker
fn clone(&self) -> LocaleFallbacker
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresourceimpl Debug for LocaleFallbacker
impl Debug for LocaleFallbacker
sourceimpl PartialEq<LocaleFallbacker> for LocaleFallbacker
impl PartialEq<LocaleFallbacker> for LocaleFallbacker
sourcefn eq(&self, other: &LocaleFallbacker) -> bool
fn eq(&self, other: &LocaleFallbacker) -> bool
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
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Filterable for T
impl<T> Filterable for T
sourcefn 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