use crate::provider::*;
use core::ops::Deref;
use icu_collections::codepointinvliststringlist::CodePointInversionListAndStringList;
use icu_provider::{marker::ErasedMarker, prelude::*};
#[derive(Debug)]
pub struct ExemplarCharacters {
data: DataPayload<ErasedMarker<ExemplarCharactersData<'static>>>,
}
impl ExemplarCharacters {
#[inline]
pub fn as_borrowed(&self) -> ExemplarCharactersBorrowed<'_> {
ExemplarCharactersBorrowed {
data: self.data.get(),
}
}
}
#[derive(Clone, Copy, Debug)]
pub struct ExemplarCharactersBorrowed<'a> {
data: &'a ExemplarCharactersData<'a>,
}
impl<'a> Deref for ExemplarCharactersBorrowed<'a> {
type Target = CodePointInversionListAndStringList<'a>;
fn deref(&self) -> &Self::Target {
&self.data.0
}
}
impl ExemplarCharactersBorrowed<'static> {
pub const fn static_to_owned(self) -> ExemplarCharacters {
ExemplarCharacters {
data: DataPayload::from_static_ref(self.data),
}
}
}
macro_rules! make_exemplar_chars_unicode_set_property {
(
// currently unused
dyn_data_marker: $d:ident;
data_marker: $data_marker:ty;
func:
pub fn $unstable:ident();
$(#[$attr:meta])*
pub fn $compiled:ident();
) => {
impl ExemplarCharactersBorrowed<'static> {
$(#[$attr])*
#[cfg(feature = "compiled_data")]
#[inline]
pub fn $compiled(
locale: &DataLocale,
) -> Result<Self, DataError> {
Ok(ExemplarCharactersBorrowed {
data: DataProvider::<$data_marker>::load(
&crate::provider::Baked,
DataRequest {
id: DataIdentifierBorrowed::for_locale(locale),
..Default::default()
})?
.payload
.get_static()
.ok_or_else(|| DataError::custom("Baked provider didn't return static payload"))?
})
}
}
impl ExemplarCharacters {
$(#[$attr])*
#[cfg(feature = "compiled_data")]
pub fn $compiled(
locale: &DataLocale,
) -> Result<ExemplarCharactersBorrowed<'static>, DataError> {
ExemplarCharactersBorrowed::$compiled(locale)
}
#[doc = concat!("A version of [`Self::", stringify!($compiled), "()`] that uses custom data provided by a [`DataProvider`].")]
pub fn $unstable(
provider: &(impl DataProvider<$data_marker> + ?Sized),
locale: &DataLocale,
) -> Result<Self, DataError> {
Ok(Self {
data:
provider.load(
DataRequest {
id: DataIdentifierBorrowed::for_locale(locale),
..Default::default()
})?
.payload
.cast()
})
}
}
}
}
make_exemplar_chars_unicode_set_property!(
dyn_data_marker: ExemplarCharactersMain;
data_marker: LocaleExemplarCharactersMainV1;
func:
pub fn try_new_main_unstable();
pub fn try_new_main();
);
make_exemplar_chars_unicode_set_property!(
dyn_data_marker: ExemplarCharactersAuxiliary;
data_marker: LocaleExemplarCharactersAuxiliaryV1;
func:
pub fn try_new_auxiliary_unstable();
pub fn try_new_auxiliary();
);
make_exemplar_chars_unicode_set_property!(
dyn_data_marker: ExemplarCharactersPunctuation;
data_marker: LocaleExemplarCharactersPunctuationV1;
func:
pub fn try_new_punctuation_unstable();
pub fn try_new_punctuation();
);
make_exemplar_chars_unicode_set_property!(
dyn_data_marker: ExemplarCharactersNumbers;
data_marker: LocaleExemplarCharactersNumbersV1;
func:
pub fn try_new_numbers_unstable();
pub fn try_new_numbers();
);
make_exemplar_chars_unicode_set_property!(
dyn_data_marker: ExemplarCharactersIndex;
data_marker: LocaleExemplarCharactersIndexV1;
func:
pub fn try_new_index_unstable();
pub fn try_new_index();
);