From 1c0d3a91f3a2d8106976065d5633c5baef528b28 Mon Sep 17 00:00:00 2001 From: Robert Bastian Date: Mon, 3 Jul 2023 12:32:10 +0200 Subject: [PATCH 1/7] props --- .../propnames_to_short_linear4_sc_v1.data.rs | 25 +- components/properties/src/exemplar_chars.rs | 2 +- components/properties/src/maps.rs | 9 + components/properties/src/props.rs | 298 ++++++++---------- components/properties/src/provider.rs | 2 +- components/properties/src/script.rs | 9 + components/properties/src/sets.rs | 20 +- 7 files changed, 183 insertions(+), 182 deletions(-) diff --git a/components/properties/data/data/macros/propnames_to_short_linear4_sc_v1.data.rs b/components/properties/data/data/macros/propnames_to_short_linear4_sc_v1.data.rs index c7ac939c90f..71968b010bb 100644 --- a/components/properties/data/data/macros/propnames_to_short_linear4_sc_v1.data.rs +++ b/components/properties/data/data/macros/propnames_to_short_linear4_sc_v1.data.rs @@ -6,26 +6,19 @@ #[macro_export] macro_rules! __impl_propnames_to_short_linear4_sc_v1 { ($ provider : path) => { + #[clippy::msrv = "1.61"] + impl $provider { + #[doc(hidden)] + pub const SINGLETON_PROPNAMES_TO_SHORT_LINEAR4_SC_V1: &'static ::Yokeable = &icu_properties::provider::names::PropertyEnumToValueNameLinearTiny4MapV1 { map: unsafe { zerovec::ZeroVec::from_bytes_unchecked(b"ZyyyZinhArabArmnBengBopoCherCoptCyrlDsrtDevaEthiGeorGothGrekGujrGuruHaniHangHebrHiraKndaKanaKhmrLaooLatnMlymMongMymrOgamItalOryaRunrSinhSyrcTamlTeluThaaThaiTibtCansYiiiTglgHanoBuhdTagbBraiCprtLimbLinbOsmaShawTaleUgarHrktBugiGlagKharSyloTaluTfngXpeoBaliBatkBlisBrahChamCirtCyrsEgydEgyhEgypGeokHansHantHmngHungIndsJavaKaliLatfLatgLepcLinaMandMayaMeroNkooOrkhPermPhagPhnxPlrdRoroSaraSyreSyrjSyrnTengVaiiVispXsuxZxxxZzzzCariJpanLanaLyciLydiOlckRjngSaurSgnwSundMoonMteiArmiAvstCakmKoreKthiManiPhliPhlpPhlvPrtiSamrTavtZmthZsymBamuLisuNkgbSarbBassDuplElbaGranKpelLomaMendMercNarbNbatPalmSindWaraAfakJurcMrooNshuShrdSoraTakrTangWoleHluwKhojTirhAghbMahjAhomHatrModiMultPaucSiddAdlmBhksMarcNewaOsgeHanbJamoZsyeGonmSoyoZanbDogrGongMakaMedfRohgSogdSogoElymHmnpNandWchoChrsDiakKitsYeziCpmnOugrTnsaTotoVithKawi") } }; + } #[clippy::msrv = "1.61"] impl icu_provider::DataProvider for $provider { fn load(&self, req: icu_provider::DataRequest) -> Result, icu_provider::DataError> { - static UND: ::Yokeable = icu_properties::provider::names::PropertyEnumToValueNameLinearTiny4MapV1 { map: unsafe { zerovec::ZeroVec::from_bytes_unchecked(b"ZyyyZinhArabArmnBengBopoCherCoptCyrlDsrtDevaEthiGeorGothGrekGujrGuruHaniHangHebrHiraKndaKanaKhmrLaooLatnMlymMongMymrOgamItalOryaRunrSinhSyrcTamlTeluThaaThaiTibtCansYiiiTglgHanoBuhdTagbBraiCprtLimbLinbOsmaShawTaleUgarHrktBugiGlagKharSyloTaluTfngXpeoBaliBatkBlisBrahChamCirtCyrsEgydEgyhEgypGeokHansHantHmngHungIndsJavaKaliLatfLatgLepcLinaMandMayaMeroNkooOrkhPermPhagPhnxPlrdRoroSaraSyreSyrjSyrnTengVaiiVispXsuxZxxxZzzzCariJpanLanaLyciLydiOlckRjngSaurSgnwSundMoonMteiArmiAvstCakmKoreKthiManiPhliPhlpPhlvPrtiSamrTavtZmthZsymBamuLisuNkgbSarbBassDuplElbaGranKpelLomaMendMercNarbNbatPalmSindWaraAfakJurcMrooNshuShrdSoraTakrTangWoleHluwKhojTirhAghbMahjAhomHatrModiMultPaucSiddAdlmBhksMarcNewaOsgeHanbJamoZsyeGonmSoyoZanbDogrGongMakaMedfRohgSogdSogoElymHmnpNandWchoChrsDiakKitsYeziCpmnOugrTnsaTotoVithKawi") } }; - static VALUES: [&::Yokeable; 1usize] = [&UND]; - static KEYS: [&str; 1usize] = ["und"]; - let mut metadata = icu_provider::DataResponseMetadata::default(); - let payload = if let Ok(payload) = KEYS.binary_search_by(|k| req.locale.strict_cmp(k.as_bytes()).reverse()).map(|i| *unsafe { VALUES.get_unchecked(i) }) { - payload + if req.locale.is_empty() { + Ok(icu_provider::DataResponse { payload: Some(icu_provider::DataPayload::from_static_ref(Self::SINGLETON_PROPNAMES_TO_SHORT_LINEAR4_SC_V1)), metadata: Default::default() }) } else { - let mut fallback_iterator = icu_locid_transform::fallback::LocaleFallbacker::new().fallback_for(::KEY.into(), req.locale.clone()); - loop { - if let Ok(payload) = KEYS.binary_search_by(|k| fallback_iterator.get().strict_cmp(k.as_bytes()).reverse()).map(|i| *unsafe { VALUES.get_unchecked(i) }) { - metadata.locale = Some(fallback_iterator.take()); - break payload; - } - fallback_iterator.step(); - } - }; - Ok(icu_provider::DataResponse { payload: Some(icu_provider::DataPayload::from_static_ref(payload)), metadata }) + Err(icu_provider::DataErrorKind::ExtraneousLocale.with_req(::KEY, req)) + } } } }; diff --git a/components/properties/src/exemplar_chars.rs b/components/properties/src/exemplar_chars.rs index d0961447691..5c779861088 100644 --- a/components/properties/src/exemplar_chars.rs +++ b/components/properties/src/exemplar_chars.rs @@ -65,7 +65,7 @@ macro_rules! make_exemplar_chars_unicode_set_property { #[cfg(feature = "compiled_data")] $vis2 fn $constname( locale: &DataLocale, - ) -> Result { + ) -> Result { Ok(UnicodeSetData::from_data( DataProvider::<$keyed_data_marker>::load( &crate::provider::Baked, diff --git a/components/properties/src/maps.rs b/components/properties/src/maps.rs index 15f4ff43380..262f1d606c7 100644 --- a/components/properties/src/maps.rs +++ b/components/properties/src/maps.rs @@ -262,6 +262,15 @@ impl<'a, T: TrieValue> CodePointMapDataBorrowed<'a, T> { } } +impl CodePointMapDataBorrowed<'static, T> { + /// Cheaply converts a `CodePointMapDataBorrowed<'static>` into a `CodePointMapData`. + pub fn static_to_owned(self) -> CodePointMapData { + CodePointMapData { + data: DataPayload::from_static_ref(self.map), + } + } +} + impl<'a> CodePointMapDataBorrowed<'a, crate::GeneralCategory> { /// Yields an [`Iterator`] returning ranges of consecutive code points that /// have a `General_Category` value belonging to the specified [`GeneralCategoryGroup`] diff --git a/components/properties/src/props.rs b/components/properties/src/props.rs index c6141844224..c7b9e1c3d58 100644 --- a/components/properties/src/props.rs +++ b/components/properties/src/props.rs @@ -44,9 +44,7 @@ impl DataMarker for ErasedNameToEnumMapV1Marker { /// use icu::properties::GeneralCategory; /// /// let lookup = -/// GeneralCategory::name_to_enum_mapper() -/// .expect("locale should be present"); -/// let lookup = lookup.as_borrowed(); +/// GeneralCategory::name_to_enum_mapper(); /// // short name for value /// assert_eq!( /// lookup.get_strict("Lu"), @@ -102,12 +100,7 @@ impl PropertyValueNameToEnumMapper { } } - /// Construct a new one from loaded data - /// - /// Typically it is preferable to use methods on individual property value types - /// (like [`Script::get_name_to_enum_mapper()`]) instead. - #[doc(hidden)] // used for efficiency by FFI code - pub fn from_data(data: DataPayload) -> Self + pub(crate) fn from_data(data: DataPayload) -> Self where M: DataMarker>, { @@ -116,6 +109,14 @@ impl PropertyValueNameToEnumMapper { markers: PhantomData, } } + + #[doc(hidden)] // used by FFI code + pub fn erase(self) -> PropertyValueNameToEnumMapper { + PropertyValueNameToEnumMapper { + map: self.map.cast(), + markers: PhantomData, + } + } } impl PropertyValueNameToEnumMapperBorrowed<'_, T> { @@ -128,9 +129,7 @@ impl PropertyValueNameToEnumMapperBorrowed<'_, T> { /// use icu_properties::GeneralCategory; /// /// let lookup = - /// GeneralCategory::name_to_enum_mapper() - /// .expect("locale should be present"); - /// let lookup = lookup.as_borrowed(); + /// GeneralCategory::name_to_enum_mapper(); /// assert_eq!( /// lookup.get_strict_u16("Lu"), /// Some(GeneralCategory::UppercaseLetter as u16) @@ -156,9 +155,7 @@ impl PropertyValueNameToEnumMapperBorrowed<'_, T> { /// use icu_properties::GeneralCategory; /// /// let lookup = - /// GeneralCategory::name_to_enum_mapper() - /// .expect("locale should be present"); - /// let lookup = lookup.as_borrowed(); + /// GeneralCategory::name_to_enum_mapper(); /// assert_eq!( /// lookup.get_strict("Lu"), /// Some(GeneralCategory::UppercaseLetter) @@ -185,9 +182,7 @@ impl PropertyValueNameToEnumMapperBorrowed<'_, T> { /// use icu_properties::GeneralCategory; /// /// let lookup = - /// GeneralCategory::name_to_enum_mapper() - /// .expect("locale should be present"); - /// let lookup = lookup.as_borrowed(); + /// GeneralCategory::name_to_enum_mapper(); /// assert_eq!( /// lookup.get_loose_u16("Lu"), /// Some(GeneralCategory::UppercaseLetter as u16) @@ -217,9 +212,7 @@ impl PropertyValueNameToEnumMapperBorrowed<'_, T> { /// use icu_properties::GeneralCategory; /// /// let lookup = - /// GeneralCategory::name_to_enum_mapper() - /// .expect("locale should be present"); - /// let lookup = lookup.as_borrowed(); + /// GeneralCategory::name_to_enum_mapper(); /// assert_eq!( /// lookup.get_loose("Lu"), /// Some(GeneralCategory::UppercaseLetter) @@ -240,6 +233,16 @@ impl PropertyValueNameToEnumMapperBorrowed<'_, T> { } } +impl PropertyValueNameToEnumMapperBorrowed<'static, T> { + /// Cheaply converts a `PropertyValueNameToEnumMapperBorrowed<'static>` into a `PropertyValueNameToEnumMapper`. + pub fn static_to_owned(self) -> PropertyValueNameToEnumMapper { + PropertyValueNameToEnumMapper { + map: DataPayload::from_static_ref(self.map), + markers: PhantomData, + } + } +} + /// Avoid monomorphizing multiple copies of this function fn get_strict_u16(payload: &PropertyValueNameToEnumMapV1<'_>, name: &str) -> Option { // NormalizedPropertyName has no invariants so this should be free, but @@ -280,9 +283,7 @@ impl DataMarker for ErasedEnumToValueNameSparseMapV1Marker { /// use icu::properties::CanonicalCombiningClass; /// /// let lookup = CanonicalCombiningClass::enum_to_long_name_mapper( -/// ) -/// .expect("locale should be present"); -/// let lookup = lookup.as_borrowed(); +/// ); /// assert_eq!( /// lookup.get(CanonicalCombiningClass::KanaVoicing), /// Some("Kana_Voicing") @@ -343,9 +344,7 @@ impl PropertyEnumToValueNameSparseMapperBorrowed<'_, T> { /// use icu::properties::CanonicalCombiningClass; /// /// let lookup = CanonicalCombiningClass::enum_to_long_name_mapper( - /// ) - /// .expect("locale should be present"); - /// let lookup = lookup.as_borrowed(); + /// ); /// assert_eq!( /// lookup.get(CanonicalCombiningClass::KanaVoicing), /// Some("Kana_Voicing") @@ -362,6 +361,16 @@ impl PropertyEnumToValueNameSparseMapperBorrowed<'_, T> { } } +impl PropertyEnumToValueNameSparseMapperBorrowed<'static, T> { + /// Cheaply converts a `PropertyEnumToValueNameSparseMapperBorrowed<'static>` into a `PropertyEnumToValueNameSparseMapper`. + pub fn static_to_owned(self) -> PropertyEnumToValueNameSparseMapper { + PropertyEnumToValueNameSparseMapper { + map: DataPayload::from_static_ref(self.map), + markers: PhantomData, + } + } +} + /// Private marker type for PropertyEnumToValueNameLinearMapper /// to work for all properties at once #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] @@ -386,9 +395,7 @@ impl DataMarker for ErasedEnumToValueNameLinearMapV1Marker { /// use icu::properties::GeneralCategory; /// /// let lookup = GeneralCategory::enum_to_long_name_mapper( -/// ) -/// .expect("locale should be present"); -/// let lookup = lookup.as_borrowed(); +/// ); /// assert_eq!( /// lookup.get(GeneralCategory::UppercaseLetter), /// Some("Uppercase_Letter") @@ -449,9 +456,7 @@ impl PropertyEnumToValueNameLinearMapperBorrowed<'_, T> { /// use icu::properties::GeneralCategory; /// /// let lookup = GeneralCategory::enum_to_short_name_mapper( - /// ) - /// .expect("locale should be present"); - /// let lookup = lookup.as_borrowed(); + /// ); /// assert_eq!(lookup.get(GeneralCategory::UppercaseLetter), Some("Lu")); /// assert_eq!(lookup.get(GeneralCategory::DashPunctuation), Some("Pd")); /// ``` @@ -462,6 +467,16 @@ impl PropertyEnumToValueNameLinearMapperBorrowed<'_, T> { } } +impl PropertyEnumToValueNameLinearMapperBorrowed<'static, T> { + /// Cheaply converts a `PropertyEnumToValueNameLinearMapperBorrowed<'static>` into a `PropertyEnumToValueNameLinearMapper`. + pub fn static_to_owned(self) -> PropertyEnumToValueNameLinearMapper { + PropertyEnumToValueNameLinearMapper { + map: DataPayload::from_static_ref(self.map), + markers: PhantomData, + } + } +} + /// Private marker type for PropertyEnumToValueNameLinearTiny4Mapper /// to work for all properties at once #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] @@ -485,9 +500,7 @@ impl DataMarker for ErasedEnumToValueNameLinearTiny4MapV1Marker { /// use tinystr::tinystr; /// /// let lookup = -/// Script::enum_to_short_name_mapper() -/// .expect("locale should be present"); -/// let lookup = lookup.as_borrowed(); +/// Script::enum_to_short_name_mapper(); /// assert_eq!(lookup.get(Script::Brahmi), Some(tinystr!(4, "Brah"))); /// assert_eq!(lookup.get(Script::Hangul), Some(tinystr!(4, "Hang"))); /// ``` @@ -543,9 +556,7 @@ impl PropertyEnumToValueNameLinearTiny4MapperBorrowed<'_, T> { /// use tinystr::tinystr; /// /// let lookup = - /// Script::enum_to_short_name_mapper() - /// .expect("locale should be present"); - /// let lookup = lookup.as_borrowed(); + /// Script::enum_to_short_name_mapper(); /// assert_eq!(lookup.get(Script::Brahmi), Some(tinystr!(4, "Brah"))); /// assert_eq!(lookup.get(Script::Hangul), Some(tinystr!(4, "Hang"))); /// ``` @@ -555,19 +566,30 @@ impl PropertyEnumToValueNameLinearTiny4MapperBorrowed<'_, T> { self.map.map.get(prop).filter(|x| !x.is_empty()) } } + +impl PropertyEnumToValueNameLinearTiny4MapperBorrowed<'static, T> { + /// Cheaply converts a `PropertyEnumToValueNameLinearTiny4MapperBorrowed<'static>` into a `PropertyEnumToValueNameLinearTiny4Mapper`. + pub fn static_to_owned(self) -> PropertyEnumToValueNameLinearTiny4Mapper { + PropertyEnumToValueNameLinearTiny4Mapper { + map: DataPayload::from_static_ref(self.map), + markers: PhantomData, + } + } +} + macro_rules! impl_value_getter { ( // the marker type for names lookup (name_to_enum, enum_to_short_name, enum_to_long_name) - markers: $marker_n2e:ident$(, $marker_e2sn:ident, $marker_e2ln:ident)?; + markers: $marker_n2e:ident / $singleton_n2e:ident $(, $marker_e2sn:ident / $singleton_e2sn:ident, $marker_e2ln:ident / $singleton_e2ln:ident)?; impl $ty:ident { $(#[$attr_n2e:meta])* $vis_n2e:vis fn $name_n2e:ident() / $cname_n2e:ident(); $( $(#[$attr_e2sn:meta])* - $vis_e2sn:vis fn $name_e2sn:ident() / $cname_e2sn:ident() -> $mapper_e2sn:ident; + $vis_e2sn:vis fn $name_e2sn:ident() / $cname_e2sn:ident() -> $mapper_e2sn:ident / $mapper_e2snb:ident; $(#[$attr_e2ln:meta])* - $vis_e2ln:vis fn $name_e2ln:ident() / $cname_e2ln:ident() -> $mapper_e2ln:ident; + $vis_e2ln:vis fn $name_e2ln:ident() / $cname_e2ln:ident() -> $mapper_e2ln:ident / $mapper_e2lnb:ident; )? } ) => { @@ -576,9 +598,11 @@ macro_rules! impl_value_getter { /// /// ✨ **Enabled with the `"compiled_data"` feature.** #[cfg(feature = "compiled_data")] - $vis_n2e fn $cname_n2e() -> Result, DataError> { - DataProvider::<$marker_n2e>::load(&crate::provider::Baked, Default::default()) - .and_then(DataResponse::take_payload).map(PropertyValueNameToEnumMapper::from_data) + $vis_n2e fn $cname_n2e() -> PropertyValueNameToEnumMapperBorrowed<'static, $ty> { + PropertyValueNameToEnumMapperBorrowed { + map: crate::provider::Baked::$singleton_n2e, + markers: PhantomData, + } } #[doc = concat!("[`", stringify!($cname_n2e), "()`] with a runtime data provider argument.")] @@ -593,9 +617,11 @@ macro_rules! impl_value_getter { /// /// ✨ **Enabled with the `"compiled_data"` feature.** #[cfg(feature = "compiled_data")] - $vis_e2sn fn $cname_e2sn() -> Result<$mapper_e2sn<$ty>, DataError> { - DataProvider::<$marker_e2sn>::load(&crate::provider::Baked, Default::default()) - .and_then(DataResponse::take_payload).map($mapper_e2sn::from_data) + $vis_e2sn fn $cname_e2sn() -> $mapper_e2snb<'static, $ty> { + $mapper_e2snb { + map: crate::provider::Baked::$singleton_e2sn, + markers: PhantomData, + } } #[doc = concat!("[`", stringify!($cname_e2sn), "()`] with a runtime data provider argument.")] @@ -609,9 +635,11 @@ macro_rules! impl_value_getter { /// /// ✨ **Enabled with the `"compiled_data"` feature.** #[cfg(feature = "compiled_data")] - $vis_e2ln fn $cname_e2ln() -> Result<$mapper_e2ln<$ty>, DataError> { - DataProvider::<$marker_e2ln>::load(&crate::provider::Baked, Default::default()) - .and_then(DataResponse::take_payload).map($mapper_e2ln::from_data) + $vis_e2ln fn $cname_e2ln() -> $mapper_e2lnb<'static, $ty> { + $mapper_e2lnb { + map: crate::provider::Baked::$singleton_e2ln, + markers: PhantomData, + } } #[doc = concat!("[`", stringify!($cname_e2ln), "()`] with a runtime data provider argument.")] @@ -690,7 +718,7 @@ impl BidiClass { } impl_value_getter! { - markers: BidiClassNameToValueV1Marker, BidiClassValueToShortNameV1Marker, BidiClassValueToLongNameV1Marker; + markers: BidiClassNameToValueV1Marker / SINGLETON_PROPNAMES_FROM_BC_V1, BidiClassValueToShortNameV1Marker / SINGLETON_PROPNAMES_TO_SHORT_LINEAR_BC_V1, BidiClassValueToLongNameV1Marker / SINGLETON_PROPNAMES_TO_LONG_LINEAR_BC_V1; impl BidiClass { /// Return a [`PropertyValueNameToEnumMapper`], capable of looking up values /// from strings for the `Bidi_Class` enumerated property @@ -700,9 +728,7 @@ impl_value_getter! { /// ``` /// use icu::properties::BidiClass; /// - /// let lookup = BidiClass::name_to_enum_mapper() - /// .expect("locale should be present"); - /// let lookup = lookup.as_borrowed(); + /// let lookup = BidiClass::name_to_enum_mapper(); /// // short name for value /// assert_eq!(lookup.get_strict("AN"), Some(BidiClass::ArabicNumber)); /// assert_eq!(lookup.get_strict("NSM"), Some(BidiClass::NonspacingMark)); @@ -725,13 +751,11 @@ impl_value_getter! { /// ``` /// use icu::properties::BidiClass; /// - /// let lookup = BidiClass::enum_to_short_name_mapper() - /// .expect("locale should be present"); - /// let lookup = lookup.as_borrowed(); + /// let lookup = BidiClass::enum_to_short_name_mapper(); /// assert_eq!(lookup.get(BidiClass::ArabicNumber), Some("AN")); /// assert_eq!(lookup.get(BidiClass::NonspacingMark), Some("NSM")); /// ``` - pub fn get_enum_to_short_name_mapper() / enum_to_short_name_mapper() -> PropertyEnumToValueNameLinearMapper; + pub fn get_enum_to_short_name_mapper() / enum_to_short_name_mapper() -> PropertyEnumToValueNameLinearMapper / PropertyEnumToValueNameLinearMapperBorrowed; /// Return a [`PropertyEnumToValueNameLinearMapper`], capable of looking up long names /// for values of the `Bidi_Class` enumerated property /// @@ -740,13 +764,11 @@ impl_value_getter! { /// ``` /// use icu::properties::BidiClass; /// - /// let lookup = BidiClass::enum_to_long_name_mapper() - /// .expect("locale should be present"); - /// let lookup = lookup.as_borrowed(); + /// let lookup = BidiClass::enum_to_long_name_mapper(); /// assert_eq!(lookup.get(BidiClass::ArabicNumber), Some("Arabic_Number")); /// assert_eq!(lookup.get(BidiClass::NonspacingMark), Some("Nonspacing_Mark")); /// ``` - pub fn get_enum_to_long_name_mapper() / enum_to_long_name_mapper() -> PropertyEnumToValueNameLinearMapper; + pub fn get_enum_to_long_name_mapper() / enum_to_long_name_mapper() -> PropertyEnumToValueNameLinearMapper / PropertyEnumToValueNameLinearMapperBorrowed; } } @@ -836,7 +858,7 @@ pub enum GeneralCategory { } impl_value_getter! { - markers: GeneralCategoryNameToValueV1Marker, GeneralCategoryValueToShortNameV1Marker, GeneralCategoryValueToLongNameV1Marker; + markers: GeneralCategoryNameToValueV1Marker / SINGLETON_PROPNAMES_FROM_GC_V1, GeneralCategoryValueToShortNameV1Marker / SINGLETON_PROPNAMES_TO_SHORT_LINEAR_GC_V1, GeneralCategoryValueToLongNameV1Marker / SINGLETON_PROPNAMES_TO_LONG_LINEAR_GC_V1; impl GeneralCategory { /// Return a [`PropertyValueNameToEnumMapper`], capable of looking up values /// from strings for the `General_Category` enumerated property @@ -846,9 +868,7 @@ impl_value_getter! { /// ``` /// use icu::properties::GeneralCategory; /// - /// let lookup = GeneralCategory::name_to_enum_mapper() - /// .expect("locale should be present"); - /// let lookup = lookup.as_borrowed(); + /// let lookup = GeneralCategory::name_to_enum_mapper(); /// // short name for value /// assert_eq!(lookup.get_strict("Lu"), Some(GeneralCategory::UppercaseLetter)); /// assert_eq!(lookup.get_strict("Pd"), Some(GeneralCategory::DashPunctuation)); @@ -871,13 +891,11 @@ impl_value_getter! { /// ``` /// use icu::properties::GeneralCategory; /// - /// let lookup = GeneralCategory::enum_to_short_name_mapper() - /// .expect("locale should be present"); - /// let lookup = lookup.as_borrowed(); + /// let lookup = GeneralCategory::enum_to_short_name_mapper(); /// assert_eq!(lookup.get(GeneralCategory::UppercaseLetter), Some("Lu")); /// assert_eq!(lookup.get(GeneralCategory::DashPunctuation), Some("Pd")); /// ``` - pub fn get_enum_to_short_name_mapper() / enum_to_short_name_mapper() -> PropertyEnumToValueNameLinearMapper; + pub fn get_enum_to_short_name_mapper() / enum_to_short_name_mapper() -> PropertyEnumToValueNameLinearMapper / PropertyEnumToValueNameLinearMapperBorrowed; /// Return a [`PropertyEnumToValueNameLinearMapper`], capable of looking up long names /// for values of the `General_Category` enumerated property /// @@ -886,13 +904,11 @@ impl_value_getter! { /// ``` /// use icu::properties::GeneralCategory; /// - /// let lookup = GeneralCategory::enum_to_long_name_mapper() - /// .expect("locale should be present"); - /// let lookup = lookup.as_borrowed(); + /// let lookup = GeneralCategory::enum_to_long_name_mapper(); /// assert_eq!(lookup.get(GeneralCategory::UppercaseLetter), Some("Uppercase_Letter")); /// assert_eq!(lookup.get(GeneralCategory::DashPunctuation), Some("Dash_Punctuation")); /// ``` - pub fn get_enum_to_long_name_mapper() / enum_to_long_name_mapper() -> PropertyEnumToValueNameLinearMapper; + pub fn get_enum_to_long_name_mapper() / enum_to_long_name_mapper() -> PropertyEnumToValueNameLinearMapper / PropertyEnumToValueNameLinearMapperBorrowed; } } @@ -1189,7 +1205,7 @@ impl GeneralCategoryGroup { } impl_value_getter! { - markers: GeneralCategoryMaskNameToValueV1Marker; + markers: GeneralCategoryMaskNameToValueV1Marker / SINGLETON_PROPNAMES_FROM_GCM_V1; impl GeneralCategoryGroup { /// Return a [`PropertyValueNameToEnumMapper`], capable of looking up values /// from strings for the `General_Category_Mask` mask property @@ -1199,9 +1215,7 @@ impl_value_getter! { /// ``` /// use icu::properties::GeneralCategoryGroup; /// - /// let lookup = GeneralCategoryGroup::name_to_enum_mapper() - /// .expect("locale should be present"); - /// let lookup = lookup.as_borrowed(); + /// let lookup = GeneralCategoryGroup::name_to_enum_mapper(); /// // short name for value /// assert_eq!(lookup.get_strict("L"), Some(GeneralCategoryGroup::Letter)); /// assert_eq!(lookup.get_strict("LC"), Some(GeneralCategoryGroup::CasedLetter)); @@ -1431,7 +1445,7 @@ impl Script { } impl_value_getter! { - markers: ScriptNameToValueV1Marker, ScriptValueToShortNameV1Marker, ScriptValueToLongNameV1Marker; + markers: ScriptNameToValueV1Marker / SINGLETON_PROPNAMES_FROM_SC_V1, ScriptValueToShortNameV1Marker / SINGLETON_PROPNAMES_TO_SHORT_LINEAR4_SC_V1, ScriptValueToLongNameV1Marker / SINGLETON_PROPNAMES_TO_LONG_LINEAR_SC_V1; impl Script { /// Return a [`PropertyValueNameToEnumMapper`], capable of looking up values /// from strings for the `Script` enumerated property @@ -1441,9 +1455,7 @@ impl_value_getter! { /// ``` /// use icu::properties::Script; /// - /// let lookup = Script::name_to_enum_mapper() - /// .expect("locale should be present"); - /// let lookup = lookup.as_borrowed(); + /// let lookup = Script::name_to_enum_mapper(); /// // short name for value /// assert_eq!(lookup.get_strict("Brah"), Some(Script::Brahmi)); /// assert_eq!(lookup.get_strict("Hang"), Some(Script::Hangul)); @@ -1467,13 +1479,11 @@ impl_value_getter! { /// use icu::properties::Script; /// use tinystr::tinystr; /// - /// let lookup = Script::enum_to_short_name_mapper() - /// .expect("locale should be present"); - /// let lookup = lookup.as_borrowed(); + /// let lookup = Script::enum_to_short_name_mapper(); /// assert_eq!(lookup.get(Script::Brahmi), Some(tinystr!(4, "Brah"))); /// assert_eq!(lookup.get(Script::Hangul), Some(tinystr!(4, "Hang"))); /// ``` - pub fn get_enum_to_short_name_mapper() / enum_to_short_name_mapper() -> PropertyEnumToValueNameLinearTiny4Mapper; + pub fn get_enum_to_short_name_mapper() / enum_to_short_name_mapper() -> PropertyEnumToValueNameLinearTiny4Mapper / PropertyEnumToValueNameLinearTiny4MapperBorrowed; /// Return a [`PropertyEnumToValueNameLinearTiny4Mapper`], capable of looking up long names /// for values of the `Script` enumerated property /// @@ -1482,13 +1492,11 @@ impl_value_getter! { /// ``` /// use icu::properties::Script; /// - /// let lookup = Script::enum_to_long_name_mapper() - /// .expect("locale should be present"); - /// let lookup = lookup.as_borrowed(); + /// let lookup = Script::enum_to_long_name_mapper(); /// assert_eq!(lookup.get(Script::Brahmi), Some("Brahmi")); /// assert_eq!(lookup.get(Script::Hangul), Some("Hangul")); /// ``` - pub fn get_enum_to_long_name_mapper() / enum_to_long_name_mapper() -> PropertyEnumToValueNameLinearMapper; + pub fn get_enum_to_long_name_mapper() / enum_to_long_name_mapper() -> PropertyEnumToValueNameLinearMapper / PropertyEnumToValueNameLinearMapperBorrowed; } } @@ -1519,7 +1527,7 @@ impl EastAsianWidth { } impl_value_getter! { - markers: EastAsianWidthNameToValueV1Marker, EastAsianWidthValueToShortNameV1Marker, EastAsianWidthValueToLongNameV1Marker; + markers: EastAsianWidthNameToValueV1Marker / SINGLETON_PROPNAMES_FROM_EA_V1, EastAsianWidthValueToShortNameV1Marker / SINGLETON_PROPNAMES_TO_SHORT_LINEAR_EA_V1, EastAsianWidthValueToLongNameV1Marker / SINGLETON_PROPNAMES_TO_LONG_LINEAR_EA_V1; impl EastAsianWidth { /// Return a [`PropertyValueNameToEnumMapper`], capable of looking up values /// from strings for the `East_Asian_Width` enumerated property @@ -1529,9 +1537,7 @@ impl_value_getter! { /// ``` /// use icu::properties::EastAsianWidth; /// - /// let lookup = EastAsianWidth::name_to_enum_mapper() - /// .expect("locale should be present"); - /// let lookup = lookup.as_borrowed(); + /// let lookup = EastAsianWidth::name_to_enum_mapper(); /// // short name for value /// assert_eq!(lookup.get_strict("N"), Some(EastAsianWidth::Neutral)); /// assert_eq!(lookup.get_strict("H"), Some(EastAsianWidth::Halfwidth)); @@ -1554,13 +1560,11 @@ impl_value_getter! { /// ``` /// use icu::properties::EastAsianWidth; /// - /// let lookup = EastAsianWidth::enum_to_short_name_mapper() - /// .expect("locale should be present"); - /// let lookup = lookup.as_borrowed(); + /// let lookup = EastAsianWidth::enum_to_short_name_mapper(); /// assert_eq!(lookup.get(EastAsianWidth::Neutral), Some("N")); /// assert_eq!(lookup.get(EastAsianWidth::Halfwidth), Some("H")); /// ``` - pub fn get_enum_to_short_name_mapper() / enum_to_short_name_mapper() -> PropertyEnumToValueNameLinearMapper; + pub fn get_enum_to_short_name_mapper() / enum_to_short_name_mapper() -> PropertyEnumToValueNameLinearMapper / PropertyEnumToValueNameLinearMapperBorrowed; /// Return a [`PropertyEnumToValueNameLinearMapper`], capable of looking up long names /// for values of the `East_Asian_Width` enumerated property /// @@ -1569,13 +1573,11 @@ impl_value_getter! { /// ``` /// use icu::properties::EastAsianWidth; /// - /// let lookup = EastAsianWidth::enum_to_long_name_mapper() - /// .expect("locale should be present"); - /// let lookup = lookup.as_borrowed(); + /// let lookup = EastAsianWidth::enum_to_long_name_mapper(); /// assert_eq!(lookup.get(EastAsianWidth::Neutral), Some("Neutral")); /// assert_eq!(lookup.get(EastAsianWidth::Halfwidth), Some("Halfwidth")); /// ``` - pub fn get_enum_to_long_name_mapper() / enum_to_long_name_mapper() -> PropertyEnumToValueNameLinearMapper; + pub fn get_enum_to_long_name_mapper() / enum_to_long_name_mapper() -> PropertyEnumToValueNameLinearMapper / PropertyEnumToValueNameLinearMapperBorrowed; } } @@ -1643,7 +1645,7 @@ impl LineBreak { } impl_value_getter! { - markers: LineBreakNameToValueV1Marker, LineBreakValueToShortNameV1Marker, LineBreakValueToLongNameV1Marker; + markers: LineBreakNameToValueV1Marker / SINGLETON_PROPNAMES_FROM_LB_V1, LineBreakValueToShortNameV1Marker / SINGLETON_PROPNAMES_TO_SHORT_LINEAR_LB_V1, LineBreakValueToLongNameV1Marker / SINGLETON_PROPNAMES_TO_LONG_LINEAR_LB_V1; impl LineBreak { /// Return a [`PropertyValueNameToEnumMapper`], capable of looking up values /// from strings for the `Line_Break` enumerated property @@ -1653,9 +1655,7 @@ impl_value_getter! { /// ``` /// use icu::properties::LineBreak; /// - /// let lookup = LineBreak::name_to_enum_mapper() - /// .expect("locale should be present"); - /// let lookup = lookup.as_borrowed(); + /// let lookup = LineBreak::name_to_enum_mapper(); /// // short name for value /// assert_eq!(lookup.get_strict("BK"), Some(LineBreak::MandatoryBreak)); /// assert_eq!(lookup.get_strict("AL"), Some(LineBreak::Alphabetic)); @@ -1678,13 +1678,11 @@ impl_value_getter! { /// ``` /// use icu::properties::LineBreak; /// - /// let lookup = LineBreak::enum_to_short_name_mapper() - /// .expect("locale should be present"); - /// let lookup = lookup.as_borrowed(); + /// let lookup = LineBreak::enum_to_short_name_mapper(); /// assert_eq!(lookup.get(LineBreak::MandatoryBreak), Some("BK")); /// assert_eq!(lookup.get(LineBreak::Alphabetic), Some("AL")); /// ``` - pub fn get_enum_to_short_name_mapper() / enum_to_short_name_mapper() -> PropertyEnumToValueNameLinearMapper; + pub fn get_enum_to_short_name_mapper() / enum_to_short_name_mapper() -> PropertyEnumToValueNameLinearMapper / PropertyEnumToValueNameLinearMapperBorrowed; /// Return a [`PropertyEnumToValueNameLinearMapper`], capable of looking up long names /// for values of the `Line_Break` enumerated property /// @@ -1693,13 +1691,11 @@ impl_value_getter! { /// ``` /// use icu::properties::LineBreak; /// - /// let lookup = LineBreak::enum_to_long_name_mapper() - /// .expect("locale should be present"); - /// let lookup = lookup.as_borrowed(); + /// let lookup = LineBreak::enum_to_long_name_mapper(); /// assert_eq!(lookup.get(LineBreak::MandatoryBreak), Some("Mandatory_Break")); /// assert_eq!(lookup.get(LineBreak::Alphabetic), Some("Alphabetic")); /// ``` - pub fn get_enum_to_long_name_mapper() / enum_to_long_name_mapper() -> PropertyEnumToValueNameLinearMapper; + pub fn get_enum_to_long_name_mapper() / enum_to_long_name_mapper() -> PropertyEnumToValueNameLinearMapper / PropertyEnumToValueNameLinearMapperBorrowed; } } @@ -1747,7 +1743,7 @@ impl GraphemeClusterBreak { } impl_value_getter! { - markers: GraphemeClusterBreakNameToValueV1Marker, GraphemeClusterBreakValueToShortNameV1Marker, GraphemeClusterBreakValueToLongNameV1Marker; + markers: GraphemeClusterBreakNameToValueV1Marker / SINGLETON_PROPNAMES_FROM_GCB_V1, GraphemeClusterBreakValueToShortNameV1Marker / SINGLETON_PROPNAMES_TO_SHORT_LINEAR_GCB_V1, GraphemeClusterBreakValueToLongNameV1Marker / SINGLETON_PROPNAMES_TO_LONG_LINEAR_GCB_V1; impl GraphemeClusterBreak { /// Return a [`PropertyValueNameToEnumMapper`], capable of looking up values /// from strings for the `Grapheme_Cluster_Break` enumerated property @@ -1757,9 +1753,7 @@ impl_value_getter! { /// ``` /// use icu::properties::GraphemeClusterBreak; /// - /// let lookup = GraphemeClusterBreak::name_to_enum_mapper() - /// .expect("locale should be present"); - /// let lookup = lookup.as_borrowed(); + /// let lookup = GraphemeClusterBreak::name_to_enum_mapper(); /// // short name for value /// assert_eq!(lookup.get_strict("EX"), Some(GraphemeClusterBreak::Extend)); /// assert_eq!(lookup.get_strict("RI"), Some(GraphemeClusterBreak::RegionalIndicator)); @@ -1782,13 +1776,11 @@ impl_value_getter! { /// ``` /// use icu::properties::GraphemeClusterBreak; /// - /// let lookup = GraphemeClusterBreak::enum_to_short_name_mapper() - /// .expect("locale should be present"); - /// let lookup = lookup.as_borrowed(); + /// let lookup = GraphemeClusterBreak::enum_to_short_name_mapper(); /// assert_eq!(lookup.get(GraphemeClusterBreak::Extend), Some("EX")); /// assert_eq!(lookup.get(GraphemeClusterBreak::RegionalIndicator), Some("RI")); /// ``` - pub fn get_enum_to_short_name_mapper() / enum_to_short_name_mapper() -> PropertyEnumToValueNameLinearMapper; + pub fn get_enum_to_short_name_mapper() / enum_to_short_name_mapper() -> PropertyEnumToValueNameLinearMapper / PropertyEnumToValueNameLinearMapperBorrowed; /// Return a [`PropertyEnumToValueNameLinearMapper`], capable of looking up long names /// for values of the `Grapheme_Cluster_Break` enumerated property /// @@ -1797,13 +1789,11 @@ impl_value_getter! { /// ``` /// use icu::properties::GraphemeClusterBreak; /// - /// let lookup = GraphemeClusterBreak::enum_to_long_name_mapper() - /// .expect("locale should be present"); - /// let lookup = lookup.as_borrowed(); + /// let lookup = GraphemeClusterBreak::enum_to_long_name_mapper(); /// assert_eq!(lookup.get(GraphemeClusterBreak::Extend), Some("Extend")); /// assert_eq!(lookup.get(GraphemeClusterBreak::RegionalIndicator), Some("Regional_Indicator")); /// ``` - pub fn get_enum_to_long_name_mapper() / enum_to_long_name_mapper() -> PropertyEnumToValueNameLinearMapper; + pub fn get_enum_to_long_name_mapper() / enum_to_long_name_mapper() -> PropertyEnumToValueNameLinearMapper / PropertyEnumToValueNameLinearMapperBorrowed; } } @@ -1856,7 +1846,7 @@ impl WordBreak { } impl_value_getter! { - markers: WordBreakNameToValueV1Marker, WordBreakValueToShortNameV1Marker, WordBreakValueToLongNameV1Marker; + markers: WordBreakNameToValueV1Marker / SINGLETON_PROPNAMES_FROM_WB_V1, WordBreakValueToShortNameV1Marker / SINGLETON_PROPNAMES_TO_SHORT_LINEAR_WB_V1, WordBreakValueToLongNameV1Marker / SINGLETON_PROPNAMES_TO_LONG_LINEAR_WB_V1; impl WordBreak { /// Return a [`PropertyValueNameToEnumMapper`], capable of looking up values /// from strings for the `Word_Break` enumerated property @@ -1866,9 +1856,7 @@ impl_value_getter! { /// ``` /// use icu::properties::WordBreak; /// - /// let lookup = WordBreak::name_to_enum_mapper() - /// .expect("locale should be present"); - /// let lookup = lookup.as_borrowed(); + /// let lookup = WordBreak::name_to_enum_mapper(); /// // short name for value /// assert_eq!(lookup.get_strict("KA"), Some(WordBreak::Katakana)); /// assert_eq!(lookup.get_strict("LE"), Some(WordBreak::ALetter)); @@ -1891,13 +1879,11 @@ impl_value_getter! { /// ``` /// use icu::properties::WordBreak; /// - /// let lookup = WordBreak::enum_to_short_name_mapper() - /// .expect("locale should be present"); - /// let lookup = lookup.as_borrowed(); + /// let lookup = WordBreak::enum_to_short_name_mapper(); /// assert_eq!(lookup.get(WordBreak::Katakana), Some("KA")); /// assert_eq!(lookup.get(WordBreak::ALetter), Some("LE")); /// ``` - pub fn get_enum_to_short_name_mapper() / enum_to_short_name_mapper() -> PropertyEnumToValueNameLinearMapper; + pub fn get_enum_to_short_name_mapper() / enum_to_short_name_mapper() -> PropertyEnumToValueNameLinearMapper / PropertyEnumToValueNameLinearMapperBorrowed; /// Return a [`PropertyEnumToValueNameLinearMapper`], capable of looking up long names /// for values of the `Word_Break` enumerated property /// @@ -1906,13 +1892,11 @@ impl_value_getter! { /// ``` /// use icu::properties::WordBreak; /// - /// let lookup = WordBreak::enum_to_long_name_mapper() - /// .expect("locale should be present"); - /// let lookup = lookup.as_borrowed(); + /// let lookup = WordBreak::enum_to_long_name_mapper(); /// assert_eq!(lookup.get(WordBreak::Katakana), Some("Katakana")); /// assert_eq!(lookup.get(WordBreak::ALetter), Some("ALetter")); /// ``` - pub fn get_enum_to_long_name_mapper() / enum_to_long_name_mapper() -> PropertyEnumToValueNameLinearMapper; + pub fn get_enum_to_long_name_mapper() / enum_to_long_name_mapper() -> PropertyEnumToValueNameLinearMapper / PropertyEnumToValueNameLinearMapperBorrowed; } } @@ -1952,7 +1936,7 @@ impl SentenceBreak { } impl_value_getter! { - markers: SentenceBreakNameToValueV1Marker, SentenceBreakValueToShortNameV1Marker, SentenceBreakValueToLongNameV1Marker; + markers: SentenceBreakNameToValueV1Marker / SINGLETON_PROPNAMES_FROM_SB_V1, SentenceBreakValueToShortNameV1Marker / SINGLETON_PROPNAMES_TO_SHORT_LINEAR_SB_V1, SentenceBreakValueToLongNameV1Marker / SINGLETON_PROPNAMES_TO_LONG_LINEAR_SB_V1; impl SentenceBreak { /// Return a [`PropertyValueNameToEnumMapper`], capable of looking up values /// from strings for the `Sentence_Break` enumerated property @@ -1962,9 +1946,7 @@ impl_value_getter! { /// ``` /// use icu::properties::SentenceBreak; /// - /// let lookup = SentenceBreak::name_to_enum_mapper() - /// .expect("locale should be present"); - /// let lookup = lookup.as_borrowed(); + /// let lookup = SentenceBreak::name_to_enum_mapper(); /// // short name for value /// assert_eq!(lookup.get_strict("FO"), Some(SentenceBreak::Format)); /// assert_eq!(lookup.get_strict("NU"), Some(SentenceBreak::Numeric)); @@ -1987,13 +1969,11 @@ impl_value_getter! { /// ``` /// use icu::properties::SentenceBreak; /// - /// let lookup = SentenceBreak::enum_to_short_name_mapper() - /// .expect("locale should be present"); - /// let lookup = lookup.as_borrowed(); + /// let lookup = SentenceBreak::enum_to_short_name_mapper(); /// assert_eq!(lookup.get(SentenceBreak::Format), Some("FO")); /// assert_eq!(lookup.get(SentenceBreak::Numeric), Some("NU")); /// ``` - pub fn get_enum_to_short_name_mapper() / enum_to_short_name_mapper() -> PropertyEnumToValueNameLinearMapper; + pub fn get_enum_to_short_name_mapper() / enum_to_short_name_mapper() -> PropertyEnumToValueNameLinearMapper / PropertyEnumToValueNameLinearMapperBorrowed; /// Return a [`PropertyEnumToValueNameLinearMapper`], capable of looking up long names /// for values of the `Sentence_Break` enumerated property /// @@ -2002,13 +1982,11 @@ impl_value_getter! { /// ``` /// use icu::properties::SentenceBreak; /// - /// let lookup = SentenceBreak::enum_to_long_name_mapper() - /// .expect("locale should be present"); - /// let lookup = lookup.as_borrowed(); + /// let lookup = SentenceBreak::enum_to_long_name_mapper(); /// assert_eq!(lookup.get(SentenceBreak::Format), Some("Format")); /// assert_eq!(lookup.get(SentenceBreak::Numeric), Some("Numeric")); /// ``` - pub fn get_enum_to_long_name_mapper() / enum_to_long_name_mapper() -> PropertyEnumToValueNameLinearMapper; + pub fn get_enum_to_long_name_mapper() / enum_to_long_name_mapper() -> PropertyEnumToValueNameLinearMapper / PropertyEnumToValueNameLinearMapperBorrowed; } } /// Property Canonical_Combining_Class. @@ -2096,7 +2074,7 @@ impl CanonicalCombiningClass { } impl_value_getter! { - markers: CanonicalCombiningClassNameToValueV1Marker, CanonicalCombiningClassValueToShortNameV1Marker, CanonicalCombiningClassValueToLongNameV1Marker; + markers: CanonicalCombiningClassNameToValueV1Marker / SINGLETON_PROPNAMES_FROM_CCC_V1, CanonicalCombiningClassValueToShortNameV1Marker / SINGLETON_PROPNAMES_TO_SHORT_SPARSE_CCC_V1, CanonicalCombiningClassValueToLongNameV1Marker / SINGLETON_PROPNAMES_TO_LONG_SPARSE_CCC_V1; impl CanonicalCombiningClass { /// Return a [`PropertyValueNameToEnumMapper`], capable of looking up values /// from strings for the `Canonical_Combining_Class` enumerated property @@ -2106,9 +2084,7 @@ impl_value_getter! { /// ``` /// use icu::properties::CanonicalCombiningClass; /// - /// let lookup = CanonicalCombiningClass::name_to_enum_mapper() - /// .expect("locale should be present"); - /// let lookup = lookup.as_borrowed(); + /// let lookup = CanonicalCombiningClass::name_to_enum_mapper(); /// // short name for value /// assert_eq!(lookup.get_strict("AL"), Some(CanonicalCombiningClass::AboveLeft)); /// assert_eq!(lookup.get_strict("ATBL"), Some(CanonicalCombiningClass::AttachedBelowLeft)); @@ -2132,14 +2108,12 @@ impl_value_getter! { /// ``` /// use icu::properties::CanonicalCombiningClass; /// - /// let lookup = CanonicalCombiningClass::enum_to_short_name_mapper() - /// .expect("locale should be present"); - /// let lookup = lookup.as_borrowed(); + /// let lookup = CanonicalCombiningClass::enum_to_short_name_mapper(); /// assert_eq!(lookup.get(CanonicalCombiningClass::AboveLeft), Some("AL")); /// assert_eq!(lookup.get(CanonicalCombiningClass::AttachedBelowLeft), Some("ATBL")); /// assert_eq!(lookup.get(CanonicalCombiningClass::CCC10), Some("CCC10")); /// ``` - pub fn get_enum_to_short_name_mapper() / enum_to_short_name_mapper() -> PropertyEnumToValueNameSparseMapper; + pub fn get_enum_to_short_name_mapper() / enum_to_short_name_mapper() -> PropertyEnumToValueNameSparseMapper / PropertyEnumToValueNameSparseMapperBorrowed; /// Return a [`PropertyEnumToValueNameSparseMapper`], capable of looking up long names /// for values of the `Canonical_Combining_Class` enumerated property /// @@ -2148,13 +2122,11 @@ impl_value_getter! { /// ``` /// use icu::properties::CanonicalCombiningClass; /// - /// let lookup = CanonicalCombiningClass::enum_to_long_name_mapper() - /// .expect("locale should be present"); - /// let lookup = lookup.as_borrowed(); + /// let lookup = CanonicalCombiningClass::enum_to_long_name_mapper(); /// assert_eq!(lookup.get(CanonicalCombiningClass::AboveLeft), Some("Above_Left")); /// assert_eq!(lookup.get(CanonicalCombiningClass::AttachedBelowLeft), Some("Attached_Below_Left")); /// assert_eq!(lookup.get(CanonicalCombiningClass::CCC10), Some("CCC10")); /// ``` - pub fn get_enum_to_long_name_mapper() / enum_to_long_name_mapper() -> PropertyEnumToValueNameSparseMapper; + pub fn get_enum_to_long_name_mapper() / enum_to_long_name_mapper() -> PropertyEnumToValueNameSparseMapper / PropertyEnumToValueNameSparseMapperBorrowed; } } diff --git a/components/properties/src/provider.rs b/components/properties/src/provider.rs index 000bea3a648..cba8705a83d 100644 --- a/components/properties/src/provider.rs +++ b/components/properties/src/provider.rs @@ -641,7 +641,7 @@ macro_rules! expand { } impl KeyedDataMarker for $value_short_name_marker_linear4 { - const KEY: DataKey = data_key!(concat!("propnames/to/short/linear4/", $enum_s, "@1")); + const KEY: DataKey = data_key!(concat!("propnames/to/short/linear4/", $enum_s, "@1"), DataKeyMetadata::construct_internal(FallbackPriority::Language, None, None, true)); } #[doc = core::concat!("Data marker for producing long names of the values of the '", $enum_s, "' Unicode property")] diff --git a/components/properties/src/script.rs b/components/properties/src/script.rs index 7534cd9906c..cf67bb18abe 100644 --- a/components/properties/src/script.rs +++ b/components/properties/src/script.rs @@ -549,6 +549,15 @@ impl<'a> ScriptWithExtensionsBorrowed<'a> { } } +impl ScriptWithExtensionsBorrowed<'static> { + /// Cheaply converts a `ScriptWithExtensionsBorrowed<'static>` into a `ScriptWithExtensions`. + pub fn static_to_owned(self) -> ScriptWithExtensions { + ScriptWithExtensions { + data: DataPayload::from_static_ref(self.data), + } + } +} + /// Returns a [`ScriptWithExtensionsBorrowed`] struct that represents the data for the Script /// and Script_Extensions properties. /// diff --git a/components/properties/src/sets.rs b/components/properties/src/sets.rs index 03939349557..931a791fac3 100644 --- a/components/properties/src/sets.rs +++ b/components/properties/src/sets.rs @@ -106,6 +106,15 @@ pub struct CodePointSetDataBorrowed<'a> { set: &'a PropertyCodePointSetV1<'a>, } +impl CodePointSetDataBorrowed<'static> { + /// Cheaply converts a `CodePointSetDataBorrowed<'static>` into a `CodePointSetData`. + pub fn static_to_owned(self) -> CodePointSetData { + CodePointSetData { + data: DataPayload::from_static_ref(self.set), + } + } +} + impl<'a> CodePointSetDataBorrowed<'a> { /// Check if the set contains a character /// @@ -294,6 +303,15 @@ impl<'a> UnicodeSetDataBorrowed<'a> { } } +impl UnicodeSetDataBorrowed<'static> { + /// Cheaply converts a `UnicodeSetDataBorrowed<'static>` into a `UnicodeSetData`. + pub fn static_to_owned(self) -> UnicodeSetData { + UnicodeSetData { + data: DataPayload::from_static_ref(self.set), + } + } +} + pub(crate) fn load_set_data(provider: &P) -> Result where M: KeyedDataMarker>, @@ -1816,7 +1834,7 @@ pub fn for_general_category_group(enum_val: GeneralCategoryGroup) -> CodePointSe /// /// [ecma]: https://tc39.es/ecma262/#table-binary-unicode-properties #[cfg(feature = "compiled_data")] -pub fn load_for_ecma262(name: &str) -> Result { +pub fn load_for_ecma262(name: &str) -> Result, PropertiesError> { use crate::runtime::UnicodeProperty; let prop = if let Some(prop) = UnicodeProperty::parse_ecma262_name(name) { From 0c9c4fec1ad92ed279014e6e91aadede6477f821 Mon Sep 17 00:00:00 2001 From: Robert Bastian Date: Mon, 3 Jul 2023 12:38:17 +0200 Subject: [PATCH 2/7] data --- .../propnames_to_short_linear4_sc_v1.data.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/provider/testdata/data/baked/macros/propnames_to_short_linear4_sc_v1.data.rs b/provider/testdata/data/baked/macros/propnames_to_short_linear4_sc_v1.data.rs index 7d2d31b2695..71968b010bb 100644 --- a/provider/testdata/data/baked/macros/propnames_to_short_linear4_sc_v1.data.rs +++ b/provider/testdata/data/baked/macros/propnames_to_short_linear4_sc_v1.data.rs @@ -6,16 +6,18 @@ #[macro_export] macro_rules! __impl_propnames_to_short_linear4_sc_v1 { ($ provider : path) => { + #[clippy::msrv = "1.61"] + impl $provider { + #[doc(hidden)] + pub const SINGLETON_PROPNAMES_TO_SHORT_LINEAR4_SC_V1: &'static ::Yokeable = &icu_properties::provider::names::PropertyEnumToValueNameLinearTiny4MapV1 { map: unsafe { zerovec::ZeroVec::from_bytes_unchecked(b"ZyyyZinhArabArmnBengBopoCherCoptCyrlDsrtDevaEthiGeorGothGrekGujrGuruHaniHangHebrHiraKndaKanaKhmrLaooLatnMlymMongMymrOgamItalOryaRunrSinhSyrcTamlTeluThaaThaiTibtCansYiiiTglgHanoBuhdTagbBraiCprtLimbLinbOsmaShawTaleUgarHrktBugiGlagKharSyloTaluTfngXpeoBaliBatkBlisBrahChamCirtCyrsEgydEgyhEgypGeokHansHantHmngHungIndsJavaKaliLatfLatgLepcLinaMandMayaMeroNkooOrkhPermPhagPhnxPlrdRoroSaraSyreSyrjSyrnTengVaiiVispXsuxZxxxZzzzCariJpanLanaLyciLydiOlckRjngSaurSgnwSundMoonMteiArmiAvstCakmKoreKthiManiPhliPhlpPhlvPrtiSamrTavtZmthZsymBamuLisuNkgbSarbBassDuplElbaGranKpelLomaMendMercNarbNbatPalmSindWaraAfakJurcMrooNshuShrdSoraTakrTangWoleHluwKhojTirhAghbMahjAhomHatrModiMultPaucSiddAdlmBhksMarcNewaOsgeHanbJamoZsyeGonmSoyoZanbDogrGongMakaMedfRohgSogdSogoElymHmnpNandWchoChrsDiakKitsYeziCpmnOugrTnsaTotoVithKawi") } }; + } #[clippy::msrv = "1.61"] impl icu_provider::DataProvider for $provider { fn load(&self, req: icu_provider::DataRequest) -> Result, icu_provider::DataError> { - static UND: ::Yokeable = icu_properties::provider::names::PropertyEnumToValueNameLinearTiny4MapV1 { map: unsafe { zerovec::ZeroVec::from_bytes_unchecked(b"ZyyyZinhArabArmnBengBopoCherCoptCyrlDsrtDevaEthiGeorGothGrekGujrGuruHaniHangHebrHiraKndaKanaKhmrLaooLatnMlymMongMymrOgamItalOryaRunrSinhSyrcTamlTeluThaaThaiTibtCansYiiiTglgHanoBuhdTagbBraiCprtLimbLinbOsmaShawTaleUgarHrktBugiGlagKharSyloTaluTfngXpeoBaliBatkBlisBrahChamCirtCyrsEgydEgyhEgypGeokHansHantHmngHungIndsJavaKaliLatfLatgLepcLinaMandMayaMeroNkooOrkhPermPhagPhnxPlrdRoroSaraSyreSyrjSyrnTengVaiiVispXsuxZxxxZzzzCariJpanLanaLyciLydiOlckRjngSaurSgnwSundMoonMteiArmiAvstCakmKoreKthiManiPhliPhlpPhlvPrtiSamrTavtZmthZsymBamuLisuNkgbSarbBassDuplElbaGranKpelLomaMendMercNarbNbatPalmSindWaraAfakJurcMrooNshuShrdSoraTakrTangWoleHluwKhojTirhAghbMahjAhomHatrModiMultPaucSiddAdlmBhksMarcNewaOsgeHanbJamoZsyeGonmSoyoZanbDogrGongMakaMedfRohgSogdSogoElymHmnpNandWchoChrsDiakKitsYeziCpmnOugrTnsaTotoVithKawi") } }; - static VALUES: [&::Yokeable; 1usize] = [&UND]; - static KEYS: [&str; 1usize] = ["und"]; - if let Ok(payload) = KEYS.binary_search_by(|k| req.locale.strict_cmp(k.as_bytes()).reverse()).map(|i| *unsafe { VALUES.get_unchecked(i) }) { - Ok(icu_provider::DataResponse { payload: Some(icu_provider::DataPayload::from_static_ref(payload)), metadata: Default::default() }) + if req.locale.is_empty() { + Ok(icu_provider::DataResponse { payload: Some(icu_provider::DataPayload::from_static_ref(Self::SINGLETON_PROPNAMES_TO_SHORT_LINEAR4_SC_V1)), metadata: Default::default() }) } else { - Err(icu_provider::DataErrorKind::MissingLocale.with_req(::KEY, req)) + Err(icu_provider::DataErrorKind::ExtraneousLocale.with_req(::KEY, req)) } } } From 9d12a9c2cf99bc2b1854f1e2878b3d08cd138641 Mon Sep 17 00:00:00 2001 From: Robert Bastian Date: Mon, 3 Jul 2023 12:48:09 +0200 Subject: [PATCH 3/7] rev --- components/properties/src/props.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/components/properties/src/props.rs b/components/properties/src/props.rs index c7b9e1c3d58..05d9ae562ce 100644 --- a/components/properties/src/props.rs +++ b/components/properties/src/props.rs @@ -109,11 +109,18 @@ impl PropertyValueNameToEnumMapper { markers: PhantomData, } } - - #[doc(hidden)] // used by FFI code - pub fn erase(self) -> PropertyValueNameToEnumMapper { - PropertyValueNameToEnumMapper { - map: self.map.cast(), + + /// Construct a new one from loaded data + /// + /// Typically it is preferable to use methods on individual property value types + /// (like [`Script::get_name_to_enum_mapper()`]) instead. + #[doc(hidden)] // used for efficiency by FFI code + pub fn from_data(data: DataPayload) -> Self + where + M: DataMarker>, + { + Self { + map: data.cast(), markers: PhantomData, } } From 23d33d6724b7b0543e6d464f2c1d41770d3b3283 Mon Sep 17 00:00:00 2001 From: Robert Bastian Date: Mon, 3 Jul 2023 12:49:07 +0200 Subject: [PATCH 4/7] rev --- components/properties/src/props.rs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/components/properties/src/props.rs b/components/properties/src/props.rs index 05d9ae562ce..1e57c67f2e7 100644 --- a/components/properties/src/props.rs +++ b/components/properties/src/props.rs @@ -100,16 +100,6 @@ impl PropertyValueNameToEnumMapper { } } - pub(crate) fn from_data(data: DataPayload) -> Self - where - M: DataMarker>, - { - Self { - map: data.cast(), - markers: PhantomData, - } - } - /// Construct a new one from loaded data /// /// Typically it is preferable to use methods on individual property value types From 4053f04b70408199965db5c244179070a43c6ad8 Mon Sep 17 00:00:00 2001 From: Robert Bastian Date: Mon, 3 Jul 2023 12:53:14 +0200 Subject: [PATCH 5/7] gen --- ffi/diplomat/tests/missing_apis.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ffi/diplomat/tests/missing_apis.txt b/ffi/diplomat/tests/missing_apis.txt index ed4652b4523..b790826a3a5 100644 --- a/ffi/diplomat/tests/missing_apis.txt +++ b/ffi/diplomat/tests/missing_apis.txt @@ -82,6 +82,7 @@ icu::properties::exemplar_chars::exemplars_index#Fn icu::properties::exemplar_chars::exemplars_main#Fn icu::properties::exemplar_chars::exemplars_numbers#Fn icu::properties::exemplar_chars::exemplars_punctuation#Fn +icu::properties::maps::CodePointMapDataBorrowed::static_to_owned#FnInStruct icu::properties::maps::bidi_class#Fn icu::properties::maps::canonical_combining_class#Fn icu::properties::maps::east_asian_width#Fn @@ -95,15 +96,22 @@ icu::properties::names::PropertyEnumToValueNameLinearMapper#Struct icu::properties::names::PropertyEnumToValueNameLinearMapper::as_borrowed#FnInStruct icu::properties::names::PropertyEnumToValueNameLinearMapperBorrowed#Struct icu::properties::names::PropertyEnumToValueNameLinearMapperBorrowed::get#FnInStruct +icu::properties::names::PropertyEnumToValueNameLinearMapperBorrowed::static_to_owned#FnInStruct icu::properties::names::PropertyEnumToValueNameLinearTiny4Mapper#Struct icu::properties::names::PropertyEnumToValueNameLinearTiny4Mapper::as_borrowed#FnInStruct icu::properties::names::PropertyEnumToValueNameLinearTiny4MapperBorrowed#Struct icu::properties::names::PropertyEnumToValueNameLinearTiny4MapperBorrowed::get#FnInStruct +icu::properties::names::PropertyEnumToValueNameLinearTiny4MapperBorrowed::static_to_owned#FnInStruct icu::properties::names::PropertyEnumToValueNameSparseMapper#Struct icu::properties::names::PropertyEnumToValueNameSparseMapper::as_borrowed#FnInStruct icu::properties::names::PropertyEnumToValueNameSparseMapperBorrowed#Struct icu::properties::names::PropertyEnumToValueNameSparseMapperBorrowed::get#FnInStruct +icu::properties::names::PropertyEnumToValueNameSparseMapperBorrowed::static_to_owned#FnInStruct +icu::properties::names::PropertyValueNameToEnumMapperBorrowed::static_to_owned#FnInStruct +icu::properties::script::ScriptWithExtensionsBorrowed::static_to_owned#FnInStruct icu::properties::script::script_with_extensions#Fn +icu::properties::sets::CodePointSetDataBorrowed::static_to_owned#FnInStruct +icu::properties::sets::UnicodeSetDataBorrowed::static_to_owned#FnInStruct icu::properties::sets::alnum#Fn icu::properties::sets::alphabetic#Fn icu::properties::sets::ascii_hex_digit#Fn From ab492f84b47dc61ad644079c17c06979d1de7cfa Mon Sep 17 00:00:00 2001 From: Robert Bastian Date: Mon, 3 Jul 2023 14:57:01 +0200 Subject: [PATCH 6/7] more --- Cargo.lock | 1 - components/properties/Cargo.toml | 1 - components/properties/src/bidi_data.rs | 9 +++++++++ components/properties/src/maps.rs | 4 +--- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 95b74da5445..34097ec57f3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1863,7 +1863,6 @@ dependencies = [ "icu_locid_transform", "icu_properties_data", "icu_provider", - "icu_testdata", "serde", "tinystr", "unicode-bidi", diff --git a/components/properties/Cargo.toml b/components/properties/Cargo.toml index 13bc89004ea..4c281acd25e 100644 --- a/components/properties/Cargo.toml +++ b/components/properties/Cargo.toml @@ -44,7 +44,6 @@ icu_locid_transform = { version = "1.2.0", path = "../../components/locid_transf [dev-dependencies] icu = { path = "../icu", default-features = false } -icu_testdata = { path = "../../provider/testdata", default-features = false, features = ["icu_properties", "icu_locid_transform"] } [features] std = ["icu_collections/std", "icu_provider/std"] diff --git a/components/properties/src/bidi_data.rs b/components/properties/src/bidi_data.rs index 00748f4d886..b25ff3dc152 100644 --- a/components/properties/src/bidi_data.rs +++ b/components/properties/src/bidi_data.rs @@ -159,6 +159,15 @@ impl<'a> BidiAuxiliaryPropertiesBorrowed<'a> { } } +impl BidiAuxiliaryPropertiesBorrowed<'static> { + /// Cheaply converts a `BidiAuxiliaryPropertiesBorrowed<'static>` into a `BidiAuxiliaryProperties`. + pub fn static_to_owned(self) -> BidiAuxiliaryProperties { + BidiAuxiliaryProperties { + data: DataPayload::from_static_ref(self.data), + } + } +} + /// Returns a [`BidiAuxiliaryPropertiesV1`] struct that represents the data for certain /// Bidi properties. /// diff --git a/components/properties/src/maps.rs b/components/properties/src/maps.rs index 262f1d606c7..9d8f465e7e5 100644 --- a/components/properties/src/maps.rs +++ b/components/properties/src/maps.rs @@ -65,9 +65,7 @@ impl CodePointMapData { /// ``` /// use icu::properties::{maps, GeneralCategory}; /// - /// let data = - /// maps::load_general_category(&icu_testdata::unstable()) - /// .expect("The data should be valid"); + /// let data = maps::general_category().static_to_owned(); /// /// let gc = data.try_into_converted::().unwrap(); /// let gc = gc.as_borrowed(); From e614651b10c1638cde8dc0976c9c91ff0bfeb142 Mon Sep 17 00:00:00 2001 From: Robert Bastian Date: Mon, 3 Jul 2023 15:08:59 +0200 Subject: [PATCH 7/7] gen --- ffi/diplomat/tests/missing_apis.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/ffi/diplomat/tests/missing_apis.txt b/ffi/diplomat/tests/missing_apis.txt index b790826a3a5..6235b4c4585 100644 --- a/ffi/diplomat/tests/missing_apis.txt +++ b/ffi/diplomat/tests/missing_apis.txt @@ -73,6 +73,7 @@ icu::properties::bidi_data::BidiAuxiliaryProperties::from_data#FnInStruct icu::properties::bidi_data::BidiAuxiliaryPropertiesBorrowed#Struct icu::properties::bidi_data::BidiAuxiliaryPropertiesBorrowed::get32_mirroring_props#FnInStruct icu::properties::bidi_data::BidiAuxiliaryPropertiesBorrowed::get32_pairing_props#FnInStruct +icu::properties::bidi_data::BidiAuxiliaryPropertiesBorrowed::static_to_owned#FnInStruct icu::properties::bidi_data::BidiMirroringProperties#Struct icu::properties::bidi_data::BidiPairingProperties#Enum icu::properties::bidi_data::bidi_auxiliary_properties#Fn