#[diplomat::bridge]
#[diplomat::abi_rename = "icu4x_{0}_mv1"]
#[diplomat::attr(auto, namespace = "icu4x")]
pub mod ffi {
use alloc::boxed::Box;
use alloc::sync::Arc;
use core::fmt::Write;
#[cfg(any(feature = "compiled_data", feature = "buffer_provider"))]
use crate::errors::ffi::DataError;
use crate::locale_core::ffi::Locale;
#[cfg(feature = "buffer_provider")]
use crate::provider::ffi::DataProvider;
#[diplomat::enum_convert(icu_calendar::AnyCalendarKind, needs_wildcard)]
#[diplomat::rust_link(icu::calendar::AnyCalendarKind, Enum)]
pub enum AnyCalendarKind {
Iso = 0,
Gregorian = 1,
Buddhist = 2,
Japanese = 3,
JapaneseExtended = 4,
Ethiopian = 5,
EthiopianAmeteAlem = 6,
Indian = 7,
Coptic = 8,
Dangi = 9,
Chinese = 10,
Hebrew = 11,
IslamicCivil = 12,
IslamicObservational = 13,
IslamicTabular = 14,
IslamicUmmAlQura = 15,
Persian = 16,
Roc = 17,
}
impl AnyCalendarKind {
#[diplomat::rust_link(icu::calendar::AnyCalendarKind::get_for_locale, FnInEnum)]
pub fn get_for_locale(locale: &Locale) -> Option<AnyCalendarKind> {
icu_calendar::AnyCalendarKind::get_for_locale(&locale.0).map(Into::into)
}
#[diplomat::rust_link(icu::calendar::AnyCalendarKind::get_for_bcp47_value, FnInEnum)]
#[diplomat::rust_link(
icu::calendar::AnyCalendarKind::get_for_bcp47_string,
FnInEnum,
hidden
)]
#[diplomat::rust_link(
icu::calendar::AnyCalendarKind::get_for_bcp47_bytes,
FnInEnum,
hidden
)]
pub fn get_for_bcp47(s: &DiplomatStr) -> Option<AnyCalendarKind> {
icu_calendar::AnyCalendarKind::get_for_bcp47_bytes(s).map(Into::into)
}
#[diplomat::rust_link(icu::calendar::AnyCalendarKind::as_bcp47_string, FnInEnum)]
#[diplomat::rust_link(icu::calendar::AnyCalendarKind::as_bcp47_value, FnInEnum, hidden)]
#[diplomat::attr(auto, getter)]
pub fn bcp47(self, write: &mut diplomat_runtime::DiplomatWrite) {
let kind = icu_calendar::AnyCalendarKind::from(self);
let _infallible = write.write_str(kind.as_bcp47_string());
}
}
#[diplomat::opaque]
#[diplomat::transparent_convert]
#[diplomat::rust_link(icu::calendar::AnyCalendar, Enum)]
pub struct Calendar(pub Arc<icu_calendar::AnyCalendar>);
impl Calendar {
#[diplomat::rust_link(icu::calendar::AnyCalendar::try_new, FnInEnum)]
#[diplomat::attr(supports = fallible_constructors, named_constructor = "for_locale")]
#[diplomat::demo(default_constructor)]
#[cfg(feature = "compiled_data")]
pub fn create_for_locale(locale: &Locale) -> Result<Box<Calendar>, DataError> {
let prefs = (&locale.0).into();
Ok(Box::new(Calendar(Arc::new(
icu_calendar::AnyCalendar::try_new(prefs)?,
))))
}
#[diplomat::rust_link(icu::calendar::AnyCalendar::new_for_kind, FnInEnum)]
#[diplomat::attr(supports = fallible_constructors, named_constructor = "for_kind")]
#[cfg(feature = "compiled_data")]
pub fn create_for_kind(kind: AnyCalendarKind) -> Result<Box<Calendar>, DataError> {
Ok(Box::new(Calendar(Arc::new(
icu_calendar::AnyCalendar::new_for_kind(kind.into()),
))))
}
#[diplomat::rust_link(icu::calendar::AnyCalendar::try_new, FnInEnum)]
#[diplomat::attr(supports = fallible_constructors, named_constructor = "for_locale_with_provider")]
#[diplomat::demo(default_constructor)]
#[cfg(feature = "buffer_provider")]
pub fn create_for_locale_with_provider(
provider: &DataProvider,
locale: &Locale,
) -> Result<Box<Calendar>, DataError> {
let prefs = (&locale.0).into();
Ok(Box::new(Calendar(Arc::new(provider.call_constructor(
|provider| icu_calendar::AnyCalendar::try_new_with_buffer_provider(provider, prefs),
)?))))
}
#[diplomat::rust_link(icu::calendar::AnyCalendar::new_for_kind, FnInEnum)]
#[diplomat::attr(supports = fallible_constructors, named_constructor = "for_kind_with_provider")]
#[cfg(feature = "buffer_provider")]
pub fn create_for_kind_with_provider(
provider: &DataProvider,
kind: AnyCalendarKind,
) -> Result<Box<Calendar>, DataError> {
Ok(Box::new(Calendar(Arc::new(provider.call_constructor(
|provider| {
icu_calendar::AnyCalendar::try_new_for_kind_with_buffer_provider(
provider,
kind.into(),
)
},
)?))))
}
#[diplomat::rust_link(icu::calendar::AnyCalendar::kind, FnInEnum)]
#[diplomat::attr(auto, getter)]
pub fn kind(&self) -> AnyCalendarKind {
self.0.kind().into()
}
}
}