#[diplomat::bridge]
#[diplomat::abi_rename = "icu4x_{0}_mv1"]
#[diplomat::attr(auto, namespace = "icu4x")]
pub mod ffi {
use alloc::boxed::Box;
use crate::{errors::ffi::DataError, locale_core::ffi::Locale, provider::ffi::DataProvider};
#[diplomat::opaque]
#[diplomat::rust_link(icu::locale::fallback::LocaleFallbacker, Struct)]
#[diplomat::rust_link(icu::locale::fallback::LocaleFallbackerBorrowed, Struct, hidden)]
pub struct LocaleFallbacker(pub icu_locale::LocaleFallbacker);
#[diplomat::enum_convert(icu_locale::fallback::LocaleFallbackPriority, needs_wildcard)]
#[diplomat::rust_link(icu::locale::fallback::LocaleFallbackPriority, Enum)]
#[diplomat::rust_link(
icu::locale::fallback::LocaleFallbackPriority::default,
FnInEnum,
hidden
)]
pub enum LocaleFallbackPriority {
Language = 0,
Region = 1,
}
#[diplomat::rust_link(icu::locale::fallback::LocaleFallbackConfig, Struct)]
#[diplomat::rust_link(
icu::locale::fallback::LocaleFallbackConfig::default,
FnInStruct,
hidden
)]
pub struct LocaleFallbackConfig {
pub priority: LocaleFallbackPriority,
}
#[diplomat::opaque]
#[diplomat::rust_link(icu::locale::fallback::LocaleFallbacker, Struct)]
#[diplomat::rust_link(icu::locale::fallback::LocaleFallbackerWithConfig, Struct)]
pub struct LocaleFallbackerWithConfig<'a>(
pub icu_locale::fallback::LocaleFallbackerWithConfig<'a>,
);
#[diplomat::opaque]
#[diplomat::rust_link(icu::locale::fallback::LocaleFallbackIterator, Struct)]
pub struct LocaleFallbackIterator<'a>(pub icu_locale::fallback::LocaleFallbackIterator<'a, 'a>);
impl LocaleFallbacker {
#[diplomat::rust_link(icu::locale::fallback::LocaleFallbacker::new, FnInStruct)]
#[diplomat::rust_link(
icu::locale::fallback::LocaleFallbackerBorrowed::new,
FnInStruct,
hidden
)]
#[diplomat::attr(supports = fallible_constructors, constructor)]
pub fn create(provider: &DataProvider) -> Result<Box<LocaleFallbacker>, DataError> {
Ok(Box::new(LocaleFallbacker(call_constructor!(
icu_locale::LocaleFallbacker::new [r => Ok(r.static_to_owned())],
icu_locale::LocaleFallbacker::try_new_with_any_provider,
icu_locale::LocaleFallbacker::try_new_with_buffer_provider,
provider,
)?)))
}
#[diplomat::rust_link(
icu::locale::fallback::LocaleFallbacker::new_without_data,
FnInStruct
)]
#[diplomat::attr(supports = fallible_constructors, named_constructor)]
pub fn without_data() -> Box<LocaleFallbacker> {
Box::new(LocaleFallbacker(
icu_locale::LocaleFallbacker::new_without_data(),
))
}
#[diplomat::rust_link(icu::locale::fallback::LocaleFallbacker::for_config, FnInStruct)]
#[diplomat::rust_link(
icu::locale::fallback::LocaleFallbackerBorrowed::for_config,
FnInStruct,
hidden
)]
pub fn for_config<'a>(
&'a self,
config: LocaleFallbackConfig,
) -> Box<LocaleFallbackerWithConfig<'a>> {
Box::new(LocaleFallbackerWithConfig(self.0.for_config({
let mut c = icu_locale::fallback::LocaleFallbackConfig::default();
c.priority = config.priority.into();
c
})))
}
}
impl<'a> LocaleFallbackerWithConfig<'a> {
#[diplomat::rust_link(icu::locale::fallback::LocaleFallbacker::fallback_for, FnInStruct)]
#[diplomat::rust_link(
icu::locale::fallback::LocaleFallbackerBorrowed::fallback_for,
FnInStruct,
hidden
)]
#[diplomat::rust_link(
icu::locale::fallback::LocaleFallbackerWithConfig::fallback_for,
FnInStruct,
hidden
)]
pub fn fallback_for_locale<'b: 'a, 'temp>(
&'b self,
locale: &'temp Locale,
) -> Box<LocaleFallbackIterator<'a>> {
Box::new(LocaleFallbackIterator(
self.0.fallback_for((&locale.0).into()),
))
}
}
impl<'a> LocaleFallbackIterator<'a> {
#[diplomat::attr(auto, iterator)]
#[diplomat::rust_link(
icu::locale::fallback::LocaleFallbackIterator::get,
FnInStruct,
hidden
)]
#[diplomat::rust_link(
icu::locale::fallback::LocaleFallbackIterator::step,
FnInStruct,
hidden
)]
#[diplomat::rust_link(
icu::locale::fallback::LocaleFallbackIterator::take,
FnInStruct,
hidden
)]
pub fn next(&mut self) -> Option<Box<Locale>> {
let current = self.0.get();
if current.is_default() {
None
} else {
let current = current.clone();
self.0.step();
Some(Box::new(Locale(current.into_locale())))
}
}
}
}