#[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;
use crate::errors::ffi::DataError;
use crate::locale_core::ffi::Locale;
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::new_for_locale, FnInEnum)]
#[diplomat::attr(supports = fallible_constructors, named_constructor = "for_locale")]
#[diplomat::demo(default_constructor)]
pub fn create_for_locale(
provider: &DataProvider,
locale: &Locale,
) -> Result<Box<Calendar>, DataError> {
let locale = locale.to_datalocale();
Ok(Box::new(Calendar(Arc::new(call_constructor!(
icu_calendar::AnyCalendar::new_for_locale [r => Ok(r)],
icu_calendar::AnyCalendar::try_new_for_locale_with_any_provider,
icu_calendar::AnyCalendar::try_new_for_locale_with_buffer_provider,
provider,
&locale
)?))))
}
#[diplomat::rust_link(icu::calendar::AnyCalendar::new, FnInEnum)]
#[diplomat::attr(supports = fallible_constructors, named_constructor = "for_kind")]
pub fn create_for_kind(
provider: &DataProvider,
kind: AnyCalendarKind,
) -> Result<Box<Calendar>, DataError> {
Ok(Box::new(Calendar(Arc::new(call_constructor!(
icu_calendar::AnyCalendar::new [r => Ok(r)],
icu_calendar::AnyCalendar::try_new_with_any_provider,
icu_calendar::AnyCalendar::try_new_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()
}
}
}