#[diplomat::bridge]
pub mod ffi {
use alloc::boxed::Box;
use alloc::sync::Arc;
use core::fmt::Write;
use icu_calendar::{AnyCalendar, AnyCalendarKind};
use crate::errors::ffi::ICU4XError;
use crate::locale::ffi::ICU4XLocale;
use crate::provider::ffi::ICU4XDataProvider;
#[diplomat::enum_convert(AnyCalendarKind, needs_wildcard)]
#[diplomat::rust_link(icu::calendar::AnyCalendarKind, Enum)]
pub enum ICU4XAnyCalendarKind {
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 ICU4XAnyCalendarKind {
#[diplomat::rust_link(icu::calendar::AnyCalendarKind::get_for_locale, FnInEnum)]
pub fn get_for_locale(locale: &ICU4XLocale) -> Option<ICU4XAnyCalendarKind> {
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<ICU4XAnyCalendarKind> {
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(supports = accessors, getter)]
pub fn bcp47(
self,
write: &mut diplomat_runtime::DiplomatWriteable,
) -> Result<(), ICU4XError> {
let kind = AnyCalendarKind::from(self);
Ok(write.write_str(kind.as_bcp47_string())?)
}
}
#[diplomat::opaque]
#[diplomat::transparent_convert]
#[diplomat::rust_link(icu::calendar::AnyCalendar, Enum)]
pub struct ICU4XCalendar(pub Arc<AnyCalendar>);
impl ICU4XCalendar {
#[diplomat::rust_link(icu::calendar::AnyCalendar::new_for_locale, FnInEnum)]
#[diplomat::attr(all(supports = constructors, supports = fallible_constructors, supports = named_constructors), named_constructor = "for_locale")]
pub fn create_for_locale(
provider: &ICU4XDataProvider,
locale: &ICU4XLocale,
) -> Result<Box<ICU4XCalendar>, ICU4XError> {
let locale = locale.to_datalocale();
Ok(Box::new(ICU4XCalendar(Arc::new(call_constructor!(
AnyCalendar::new_for_locale [r => Ok(r)],
AnyCalendar::try_new_for_locale_with_any_provider,
AnyCalendar::try_new_for_locale_with_buffer_provider,
provider,
&locale
)?))))
}
#[diplomat::rust_link(icu::calendar::AnyCalendar::new, FnInEnum)]
#[diplomat::attr(all(supports = constructors, supports = fallible_constructors, supports = named_constructors), named_constructor = "for_kind")]
pub fn create_for_kind(
provider: &ICU4XDataProvider,
kind: ICU4XAnyCalendarKind,
) -> Result<Box<ICU4XCalendar>, ICU4XError> {
Ok(Box::new(ICU4XCalendar(Arc::new(call_constructor!(
AnyCalendar::new [r => Ok(r)],
AnyCalendar::try_new_with_any_provider,
AnyCalendar::try_new_with_buffer_provider,
provider,
kind.into()
)?))))
}
#[diplomat::rust_link(icu::calendar::AnyCalendar::kind, FnInEnum)]
#[diplomat::attr(supports = accessors, getter)]
pub fn kind(&self) -> ICU4XAnyCalendarKind {
self.0.kind().into()
}
}
}