pub struct LocaleFallbacker { /* private fields */ }Expand description
Implements the algorithm defined in UTS #35: Locale Inheritance and Matching.
Note that this implementation performs some additional steps compared to the UTS #35 algorithm. See the design doc for a detailed description and #2243 to track alignment with UTS #35.
If running fallback in a loop, use DataLocale::is_und() to break from the loop.
§Examples
use icu::locid::locale;
use icu::locid_transform::fallback::LocaleFallbacker;
// Set up a LocaleFallbacker with data.
let fallbacker = LocaleFallbacker::new();
// Create a LocaleFallbackerIterator with a default configuration.
// By default, uses language priority with no additional extension keywords.
let mut fallback_iterator = fallbacker
.for_config(Default::default())
.fallback_for(locale!("hi-Latn-IN").into());
// Run the algorithm and check the results.
assert_eq!(fallback_iterator.get(), &locale!("hi-Latn-IN").into());
fallback_iterator.step();
assert_eq!(fallback_iterator.get(), &locale!("hi-Latn").into());
fallback_iterator.step();
assert_eq!(fallback_iterator.get(), &locale!("en-IN").into());
fallback_iterator.step();
assert_eq!(fallback_iterator.get(), &locale!("en-001").into());
fallback_iterator.step();
assert_eq!(fallback_iterator.get(), &locale!("en").into());
fallback_iterator.step();
assert_eq!(fallback_iterator.get(), &locale!("und").into());Implementations§
Source§impl LocaleFallbacker
impl LocaleFallbacker
Sourcepub const fn new<'a>() -> LocaleFallbackerBorrowed<'a>
pub const fn new<'a>() -> LocaleFallbackerBorrowed<'a>
Creates a LocaleFallbacker with compiled fallback data (likely subtags and parent locales).
✨ Enabled with the compiled_data Cargo feature.
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>
A version of [Self :: new] that uses custom data provided by an AnyProvider.
Sourcepub fn try_new_unstable<P>(provider: &P) -> Result<Self, DataError>
pub fn try_new_unstable<P>(provider: &P) -> Result<Self, DataError>
A version of Self::new that uses custom data provided by a DataProvider.
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<'_>
Associates a configuration with this fallbacker.
Sourcepub fn as_borrowed(&self) -> LocaleFallbackerBorrowed<'_>
pub fn as_borrowed(&self) -> LocaleFallbackerBorrowed<'_>
Creates a borrowed version of this fallbacker for performance.
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 512 bytes