diff --git a/components/casemap/src/set.rs b/components/casemap/src/set.rs index 34d5b332764..fd7478c4355 100644 --- a/components/casemap/src/set.rs +++ b/components/casemap/src/set.rs @@ -12,6 +12,9 @@ use icu_collections::codepointinvlist::CodePointInversionListBuilder; /// will be some kind of set over codepoints and strings, or something that /// can be built into one. /// +/// An implementation is provided for [`CodePointInversionListBuilder`], but users are encouraged +/// to implement this trait on their own collections as needed. +/// /// [`CaseMapCloser::add_string_case_closure_to()`]: crate::CaseMapCloser::add_string_case_closure_to /// [`CaseMapCloser::add_case_closure_to()`]: crate::CaseMapCloser::add_case_closure_to pub trait ClosureSink { diff --git a/components/collections/src/codepointtrie/cptrie.rs b/components/collections/src/codepointtrie/cptrie.rs index 8c688b0f751..5755e1fd60d 100644 --- a/components/collections/src/codepointtrie/cptrie.rs +++ b/components/collections/src/codepointtrie/cptrie.rs @@ -53,6 +53,8 @@ pub enum TrieType { /// A trait representing the values stored in the data array of a [`CodePointTrie`]. /// This trait is used as a type parameter in constructing a `CodePointTrie`. +/// +/// This trait can be implemented on anything that can be represented as a u32s worth of data. pub trait TrieValue: Copy + Eq + PartialEq + zerovec::ule::AsULE + 'static { /// Last-resort fallback value to return if we cannot read data from the trie. /// diff --git a/components/datetime/src/scaffold/calendar.rs b/components/datetime/src/scaffold/calendar.rs index 5c45429e8b1..261dfda8d97 100644 --- a/components/datetime/src/scaffold/calendar.rs +++ b/components/datetime/src/scaffold/calendar.rs @@ -20,16 +20,20 @@ use icu_provider::marker::NeverMarker; use icu_provider::prelude::*; use icu_timezone::{DateTime, Time, TimeZoneInfo, TimeZoneModel, UtcOffset, ZonedDateTime}; +mod private { + pub trait Sealed {} +} + /// A calendar that can be found in CLDR. /// /// New implementors of this trait will likely also wish to modify `get_era_code_map()` /// in the CLDR transformer to support any new era maps. /// ///
-/// 🚧 This trait is considered unstable; it may change at any time, in breaking or non-breaking ways, -/// including in SemVer minor releases. Do not implement this trait in userland. +/// 🚫 This trait is sealed; it cannot be implemented by user code. If an API requests an item that implements this +/// trait, please consider using a type from the implementors listed below. ///
-pub trait CldrCalendar: UnstableSealed { +pub trait CldrCalendar: private::Sealed { /// The data marker for loading year symbols for this calendar. type YearNamesV1Marker: DataMarker>; @@ -40,60 +44,70 @@ pub trait CldrCalendar: UnstableSealed { type SkeletaV1Marker: DataMarker>; } +impl private::Sealed for () {} impl CldrCalendar for () { type YearNamesV1Marker = NeverMarker>; type MonthNamesV1Marker = NeverMarker>; type SkeletaV1Marker = NeverMarker>; } +impl private::Sealed for Buddhist {} impl CldrCalendar for Buddhist { type YearNamesV1Marker = BuddhistYearNamesV1Marker; type MonthNamesV1Marker = BuddhistMonthNamesV1Marker; type SkeletaV1Marker = BuddhistDateNeoSkeletonPatternsV1Marker; } +impl private::Sealed for Chinese {} impl CldrCalendar for Chinese { type YearNamesV1Marker = ChineseYearNamesV1Marker; type MonthNamesV1Marker = ChineseMonthNamesV1Marker; type SkeletaV1Marker = ChineseDateNeoSkeletonPatternsV1Marker; } +impl private::Sealed for Coptic {} impl CldrCalendar for Coptic { type YearNamesV1Marker = CopticYearNamesV1Marker; type MonthNamesV1Marker = CopticMonthNamesV1Marker; type SkeletaV1Marker = CopticDateNeoSkeletonPatternsV1Marker; } +impl private::Sealed for Dangi {} impl CldrCalendar for Dangi { type YearNamesV1Marker = DangiYearNamesV1Marker; type MonthNamesV1Marker = DangiMonthNamesV1Marker; type SkeletaV1Marker = DangiDateNeoSkeletonPatternsV1Marker; } +impl private::Sealed for Ethiopian {} impl CldrCalendar for Ethiopian { type YearNamesV1Marker = EthiopianYearNamesV1Marker; type MonthNamesV1Marker = EthiopianMonthNamesV1Marker; type SkeletaV1Marker = EthiopianDateNeoSkeletonPatternsV1Marker; } +impl private::Sealed for Gregorian {} impl CldrCalendar for Gregorian { type YearNamesV1Marker = GregorianYearNamesV1Marker; type MonthNamesV1Marker = GregorianMonthNamesV1Marker; type SkeletaV1Marker = GregorianDateNeoSkeletonPatternsV1Marker; } +impl private::Sealed for Hebrew {} impl CldrCalendar for Hebrew { type YearNamesV1Marker = HebrewYearNamesV1Marker; type MonthNamesV1Marker = HebrewMonthNamesV1Marker; type SkeletaV1Marker = HebrewDateNeoSkeletonPatternsV1Marker; } +impl private::Sealed for Indian {} impl CldrCalendar for Indian { type YearNamesV1Marker = IndianYearNamesV1Marker; type MonthNamesV1Marker = IndianMonthNamesV1Marker; type SkeletaV1Marker = IndianDateNeoSkeletonPatternsV1Marker; } +impl private::Sealed for IslamicCivil {} impl CldrCalendar for IslamicCivil { // this value is not actually a valid identifier for this calendar, // however since we are overriding is_identifier_allowed_for_calendar we are using @@ -103,42 +117,49 @@ impl CldrCalendar for IslamicCivil { type SkeletaV1Marker = IslamicDateNeoSkeletonPatternsV1Marker; } +impl private::Sealed for IslamicObservational {} impl CldrCalendar for IslamicObservational { type YearNamesV1Marker = IslamicYearNamesV1Marker; type MonthNamesV1Marker = IslamicMonthNamesV1Marker; type SkeletaV1Marker = IslamicDateNeoSkeletonPatternsV1Marker; } +impl private::Sealed for IslamicTabular {} impl CldrCalendar for IslamicTabular { type YearNamesV1Marker = IslamicYearNamesV1Marker; type MonthNamesV1Marker = IslamicMonthNamesV1Marker; type SkeletaV1Marker = IslamicDateNeoSkeletonPatternsV1Marker; } +impl private::Sealed for IslamicUmmAlQura {} impl CldrCalendar for IslamicUmmAlQura { type YearNamesV1Marker = IslamicYearNamesV1Marker; type MonthNamesV1Marker = IslamicMonthNamesV1Marker; type SkeletaV1Marker = IslamicDateNeoSkeletonPatternsV1Marker; } +impl private::Sealed for Japanese {} impl CldrCalendar for Japanese { type YearNamesV1Marker = JapaneseYearNamesV1Marker; type MonthNamesV1Marker = JapaneseMonthNamesV1Marker; type SkeletaV1Marker = JapaneseDateNeoSkeletonPatternsV1Marker; } +impl private::Sealed for JapaneseExtended {} impl CldrCalendar for JapaneseExtended { type YearNamesV1Marker = JapaneseExtendedYearNamesV1Marker; type MonthNamesV1Marker = JapaneseExtendedMonthNamesV1Marker; type SkeletaV1Marker = JapaneseExtendedDateNeoSkeletonPatternsV1Marker; } +impl private::Sealed for Persian {} impl CldrCalendar for Persian { type YearNamesV1Marker = PersianYearNamesV1Marker; type MonthNamesV1Marker = PersianMonthNamesV1Marker; type SkeletaV1Marker = PersianDateNeoSkeletonPatternsV1Marker; } +impl private::Sealed for Roc {} impl CldrCalendar for Roc { type YearNamesV1Marker = RocYearNamesV1Marker; type MonthNamesV1Marker = RocMonthNamesV1Marker; @@ -169,6 +190,11 @@ impl UnstableSealed for Roc {} /// [`DynamicDataMarker`]. For example, this trait can be implemented for [`YearNamesV1Marker`]. /// /// This trait serves as a building block for a cross-calendar [`BoundDataProvider`]. +/// +///
+/// 🚧 This trait is considered unstable; it may change at any time, in breaking or non-breaking ways, +/// including in SemVer minor releases. Do not implement this trait in userland unless you are prepared for things to occasionally break. +///
pub trait CalMarkers: UnstableSealed where M: DynamicDataMarker, @@ -382,6 +408,7 @@ impl_load_any_calendar!([ ]); /// A type that can be converted into a specific calendar system. +// This trait is implementable pub trait ConvertCalendar { /// The converted type. This can be the same as the receiver type. type Converted<'a>: Sized; @@ -439,6 +466,7 @@ impl ConvertCalendar for TimeZoneInfo { } /// An input that may be associated with a specific runtime calendar. +// This trait is implementable pub trait InSameCalendar { /// Checks whether this type is compatible with the given calendar. /// @@ -512,6 +540,7 @@ impl InSameCalendar for TimeZoneInfo { } /// An input associated with a fixed, static calendar. +// This trait is implementable pub trait InFixedCalendar {} impl> InFixedCalendar for Date {} diff --git a/components/datetime/src/scaffold/fieldset_traits.rs b/components/datetime/src/scaffold/fieldset_traits.rs index 1e60d365fb4..f5c9f8fc0cf 100644 --- a/components/datetime/src/scaffold/fieldset_traits.rs +++ b/components/datetime/src/scaffold/fieldset_traits.rs @@ -28,6 +28,11 @@ use icu_timezone::{ /// (input types only). /// /// This is a sealed trait implemented on field set markers. +/// +///
+/// 🚧 This trait is considered unstable; it may change at any time, in breaking or non-breaking ways, +/// including in SemVer minor releases. Do not implement this trait in userland unless you are prepared for things to occasionally break. +///
pub trait DateInputMarkers: UnstableSealed { /// Marker for resolving the year input field. type YearInput: IntoOption; @@ -45,6 +50,11 @@ pub trait DateInputMarkers: UnstableSealed { /// (data markers only). /// /// This is a sealed trait implemented on field set markers. +/// +///
+/// 🚧 This trait is considered unstable; it may change at any time, in breaking or non-breaking ways, +/// including in SemVer minor releases. Do not implement this trait in userland unless you are prepared for things to occasionally break. +///
pub trait TypedDateDataMarkers: UnstableSealed { /// Marker for loading date skeleton patterns. type DateSkeletonPatternsV1Marker: DataMarker>; @@ -60,6 +70,11 @@ pub trait TypedDateDataMarkers: UnstableSealed { /// (data markers only). /// /// This is a sealed trait implemented on field set markers. +/// +///
+/// 🚧 This trait is considered unstable; it may change at any time, in breaking or non-breaking ways, +/// including in SemVer minor releases. Do not implement this trait in userland unless you are prepared for things to occasionally break. +///
pub trait DateDataMarkers: UnstableSealed { /// Cross-calendar data markers for date skeleta. type Skel: CalMarkers; @@ -75,6 +90,11 @@ pub trait DateDataMarkers: UnstableSealed { /// (input types and data markers). /// /// This is a sealed trait implemented on field set markers. +/// +///
+/// 🚧 This trait is considered unstable; it may change at any time, in breaking or non-breaking ways, +/// including in SemVer minor releases. Do not implement this trait in userland unless you are prepared for things to occasionally break. +///
pub trait TimeMarkers: UnstableSealed { /// Marker for resolving the day-of-month input field. type HourInput: IntoOption; @@ -94,6 +114,11 @@ pub trait TimeMarkers: UnstableSealed { /// (input types and data markers). /// /// This is a sealed trait implemented on field set markers. +/// +///
+/// 🚧 This trait is considered unstable; it may change at any time, in breaking or non-breaking ways, +/// including in SemVer minor releases. Do not implement this trait in userland unless you are prepared for things to occasionally break. +///
pub trait ZoneMarkers: UnstableSealed { /// Marker for resolving the time zone id input field. type TimeZoneIdInput: IntoOption; @@ -123,6 +148,11 @@ pub trait ZoneMarkers: UnstableSealed { /// required for datetime formatting. /// /// This is a sealed trait implemented on field set markers. +/// +///
+/// 🚧 This trait is considered unstable; it may change at any time, in breaking or non-breaking ways, +/// including in SemVer minor releases. Do not implement this trait in userland unless you are prepared for things to occasionally break. +///
pub trait DateTimeMarkers: UnstableSealed + DateTimeNamesMarker { /// Associated types for date formatting. /// @@ -156,6 +186,7 @@ pub trait DateTimeMarkers: UnstableSealed + DateTimeNamesMarker { /// - [`TimeZoneInfo`](icu_timezone::TimeZoneInfo) /// /// [`fieldsets::YMD`]: crate::fieldsets::YMD +// This trait is implicitly sealed due to sealed supertraits pub trait AllInputMarkers: GetField<::YearInput> + GetField<::MonthInput> @@ -204,6 +235,7 @@ where /// /// This trait is implemented on all providers that support datetime formatting, /// including [`crate::provider::Baked`]. +// This trait is implicitly sealed due to sealed supertraits pub trait AllFixedCalendarFormattingDataMarkers: DataProvider<>::YearNamesV1Marker> + DataProvider<>::MonthNamesV1Marker> @@ -256,6 +288,7 @@ where /// /// This trait is implemented on all providers that support datetime formatting, /// including [`crate::provider::Baked`]. +// This trait is implicitly sealed due to sealed supertraits pub trait AllAnyCalendarFormattingDataMarkers: DataProvider<<::Year as CalMarkers>::Buddhist> + DataProvider<<::Year as CalMarkers>::Chinese> @@ -400,6 +433,7 @@ where /// Trait to consolidate data provider markers external to this crate /// for datetime formatting with a fixed calendar. +// This trait is implicitly sealed due to sealed supertraits pub trait AllFixedCalendarExternalDataMarkers: DataProvider + DataProvider { @@ -412,6 +446,7 @@ impl AllFixedCalendarExternalDataMarkers for T where /// Trait to consolidate data provider markers external to this crate /// for datetime formatting with any calendar. +// This trait is implicitly sealed due to sealed supertraits pub trait AllAnyCalendarExternalDataMarkers: DataProvider + DataProvider diff --git a/components/datetime/src/scaffold/get_field.rs b/components/datetime/src/scaffold/get_field.rs index 77b72a33f9d..c3056485451 100644 --- a/components/datetime/src/scaffold/get_field.rs +++ b/components/datetime/src/scaffold/get_field.rs @@ -17,6 +17,11 @@ use super::UnstableSealed; /// A type that can return a certain field `T`. /// /// This is used as a bound on various datetime functions. +/// +///
+/// 🚧 This trait is considered unstable; it may change at any time, in breaking or non-breaking ways, +/// including in SemVer minor releases. Do not implement this trait in userland unless you are prepared for things to occasionally break. +///
pub trait GetField: UnstableSealed { /// Returns the value of this trait's field `T`. fn get_field(&self) -> T; diff --git a/components/datetime/src/scaffold/mod.rs b/components/datetime/src/scaffold/mod.rs index 0e9671c0e2f..1885bf2ca82 100644 --- a/components/datetime/src/scaffold/mod.rs +++ b/components/datetime/src/scaffold/mod.rs @@ -51,6 +51,6 @@ pub(crate) use names_storage::OptionalNames; /// ///
/// 🚧 This trait is considered unstable; it may change at any time, in breaking or non-breaking ways, -/// including in SemVer minor releases. Do not implement this trait in userland. +/// including in SemVer minor releases. Do not implement this trait in userland unless you are prepared for things to occasionally break. ///
pub trait UnstableSealed {} diff --git a/components/datetime/src/scaffold/names_storage.rs b/components/datetime/src/scaffold/names_storage.rs index 2ca8c144c9d..31dcc66eff3 100644 --- a/components/datetime/src/scaffold/names_storage.rs +++ b/components/datetime/src/scaffold/names_storage.rs @@ -19,6 +19,11 @@ use super::UnstableSealed; /// This trait allows for types that contain data for some but not all types of datetime names, /// allowing for reduced stack size. For example, a type could contain year and month names but /// not weekday, day period, or time zone names. +/// +///
+/// 🚧 This trait is considered unstable; it may change at any time, in breaking or non-breaking ways, +/// including in SemVer minor releases. Do not implement this trait in userland unless you are prepared for things to occasionally break. +///
#[allow(missing_docs)] pub trait DateTimeNamesMarker: UnstableSealed { type YearNames: NamesContainer; @@ -35,6 +40,11 @@ pub trait DateTimeNamesMarker: UnstableSealed { } /// Trait that associates a container for a payload parameterized by the given variables. +/// +///
+/// 🚧 This trait is considered unstable; it may change at any time, in breaking or non-breaking ways, +/// including in SemVer minor releases. Do not implement this trait in userland unless you are prepared for things to occasionally break. +///
#[allow(missing_docs)] pub trait NamesContainer: UnstableSealed where @@ -100,6 +110,11 @@ impl MaybePayloadError { /// a value depending on the type parameter `Variables`. /// /// Helper trait for [`DateTimeNamesMarker`]. +/// +///
+/// 🚧 This trait is considered unstable; it may change at any time, in breaking or non-breaking ways, +/// including in SemVer minor releases. Do not implement this trait in userland unless you are prepared for things to occasionally break. +///
#[allow(missing_docs)] pub trait MaybePayload: UnstableSealed { fn new_empty() -> Self; @@ -334,6 +349,7 @@ where /// is_trait_implemented::(); /// ``` #[allow(missing_docs)] +// This trait is implicitly sealed due to sealed supertraits pub trait DateTimeNamesFrom: DateTimeNamesMarker { fn map_year_names( other: >::Container, diff --git a/components/experimental/src/transliterate/transliterator/replaceable.rs b/components/experimental/src/transliterate/transliterator/replaceable.rs index 37dd944e31e..15ce2e51b28 100644 --- a/components/experimental/src/transliterate/transliterator/replaceable.rs +++ b/components/experimental/src/transliterate/transliterator/replaceable.rs @@ -579,6 +579,11 @@ pub(super) struct Reverse; /// The direction a match can be applied. Used in [`Utf8Matcher`]. /// /// See [`Forward`] and [`Reverse`] for implementors. +/// +///
+/// 🚫 This trait is sealed; it cannot be implemented by user code. If an API requests an item that implements this +/// trait, please consider using a type from the implementors listed below. +///
pub(super) trait MatchDirection: sealed::Sealed {} impl MatchDirection for Forward {} impl MatchDirection for Reverse {} diff --git a/components/pattern/src/common.rs b/components/pattern/src/common.rs index 04ecaa12e95..aa68d7dfd4e 100644 --- a/components/pattern/src/common.rs +++ b/components/pattern/src/common.rs @@ -62,6 +62,11 @@ where /// /// The trait has no public methods and is not implementable outside of this crate. /// +///
+/// 🚫 This trait is sealed; it cannot be implemented by user code. If an API requests an item that implements this +/// trait, please consider using a type from the implementors listed below. +///
+/// /// [`Pattern`]: crate::Pattern // Debug so that `#[derive(Debug)]` on types generic in `PatternBackend` works pub trait PatternBackend: crate::private::Sealed + 'static + core::fmt::Debug { @@ -115,6 +120,8 @@ pub trait PatternBackend: crate::private::Sealed + 'static + core::fmt::Debug { /// This trait can add [`Part`]s for individual literals or placeholders. The implementations /// of this trait on standard types do not add any [`Part`]s. /// +/// This trait has a blanket implementation and is therefore not implementable by user code. +/// /// # Examples /// /// A custom implementation that adds parts: diff --git a/components/properties/src/code_point_map.rs b/components/properties/src/code_point_map.rs index 843f9389420..e09ebd54ee9 100644 --- a/components/properties/src/code_point_map.rs +++ b/components/properties/src/code_point_map.rs @@ -342,6 +342,11 @@ impl<'a> CodePointMapDataBorrowed<'a, GeneralCategory> { /// The descriptions of most properties are taken from [`TR44`], the documentation for the /// Unicode Character Database. /// +///
+/// 🚫 This trait is sealed; it cannot be implemented by user code. If an API requests an item that implements this +/// trait, please consider using a type from the implementors listed below. +///
+/// /// [`TR44`]: https://www.unicode.org/reports/tr44 pub trait EnumeratedProperty: crate::private::Sealed + TrieValue { #[doc(hidden)] diff --git a/components/properties/src/code_point_set.rs b/components/properties/src/code_point_set.rs index e9406264491..7637e411688 100644 --- a/components/properties/src/code_point_set.rs +++ b/components/properties/src/code_point_set.rs @@ -204,6 +204,11 @@ impl<'a> CodePointSetDataBorrowed<'a> { /// documentation for Unicode regular expressions. In particular, Annex C of this document /// defines properties for POSIX compatibility. /// +///
+/// 🚫 This trait is sealed; it cannot be implemented by user code. If an API requests an item that implements this +/// trait, please consider using a type from the implementors listed below. +///
+/// /// [`CodePointSetData`]: crate::sets::CodePointSetData /// [`TR44`]: https://www.unicode.org/reports/tr44 /// [`TR18`]: https://www.unicode.org/reports/tr18 diff --git a/components/properties/src/emoji.rs b/components/properties/src/emoji.rs index 7116012e890..591a7dacc2e 100644 --- a/components/properties/src/emoji.rs +++ b/components/properties/src/emoji.rs @@ -144,6 +144,11 @@ impl EmojiSetDataBorrowed<'static> { } /// An Emoji set as defined by [`Unicode Technical Standard #51`](https://unicode.org/reports/tr51/#Emoji_Sets>). +/// +///
+/// 🚫 This trait is sealed; it cannot be implemented by user code. If an API requests an item that implements this +/// trait, please consider using a type from the implementors listed below. +///
pub trait EmojiSet: crate::private::Sealed { #[doc(hidden)] type DataMarker: DataMarker>; diff --git a/components/properties/src/names.rs b/components/properties/src/names.rs index 5a73ba26544..23b0f5f8336 100644 --- a/components/properties/src/names.rs +++ b/components/properties/src/names.rs @@ -650,6 +650,7 @@ pub trait ParseableEnumeratedProperty: crate::private::Sealed + TrieValue { } // Abstract over Linear/Sparse/Script representation +// This trait is implicitly sealed by not being exported. pub trait PropertyEnumToValueNameLookup { fn get(&self, prop: u32) -> Option<&str>; } diff --git a/components/segmenter/src/lib.rs b/components/segmenter/src/lib.rs index add3bd9749b..cefafebf2e3 100644 --- a/components/segmenter/src/lib.rs +++ b/components/segmenter/src/lib.rs @@ -167,3 +167,9 @@ pub use crate::word::WordBreakIteratorLatin1; pub use crate::word::WordBreakIteratorPotentiallyIllFormedUtf8; pub use crate::word::WordBreakIteratorUtf16; pub use crate::word::WordBreakIteratorUtf8; + +pub(crate) mod private { + /// Trait marking other traits that are considered unstable and should not generally be + /// implemented outside of the segmenter crate. + pub trait Sealed {} +} diff --git a/components/segmenter/src/line.rs b/components/segmenter/src/line.rs index c253b74deaa..d9b9acd23f6 100644 --- a/components/segmenter/src/line.rs +++ b/components/segmenter/src/line.rs @@ -715,22 +715,31 @@ fn is_break_utf32_by_loose( /// A trait allowing for LineBreakIterator to be generalized to multiple string iteration methods. /// /// This is implemented by ICU4X for several common string types. -pub trait LineBreakType<'l, 's> { +/// +///
+/// 🚫 This trait is sealed; it cannot be implemented by user code. If an API requests an item that implements this +/// trait, please consider using a type from the implementors listed below. +///
+pub trait LineBreakType<'l, 's>: crate::private::Sealed { /// The iterator over characters. type IterAttr: Iterator + Clone; /// The character type. type CharType: Copy + Into; + #[doc(hidden)] fn use_complex_breaking(iterator: &LineBreakIterator<'l, 's, Self>, c: Self::CharType) -> bool; + #[doc(hidden)] fn get_linebreak_property_with_rule( iterator: &LineBreakIterator<'l, 's, Self>, c: Self::CharType, ) -> u8; + #[doc(hidden)] fn get_current_position_character_len(iterator: &LineBreakIterator<'l, 's, Self>) -> usize; + #[doc(hidden)] fn handle_complex_language( iterator: &mut LineBreakIterator<'l, 's, Self>, left_codepoint: Self::CharType, @@ -1065,6 +1074,8 @@ impl<'l, 's, Y: LineBreakType<'l, 's>> LineBreakIterator<'l, 's, Y> { #[derive(Debug)] pub struct LineBreakTypeUtf8; +impl crate::private::Sealed for LineBreakTypeUtf8 {} + impl<'l, 's> LineBreakType<'l, 's> for LineBreakTypeUtf8 { type IterAttr = CharIndices<'s>; type CharType = char; @@ -1097,6 +1108,8 @@ impl<'l, 's> LineBreakType<'l, 's> for LineBreakTypeUtf8 { #[derive(Debug)] pub struct LineBreakTypePotentiallyIllFormedUtf8; +impl crate::private::Sealed for LineBreakTypePotentiallyIllFormedUtf8 {} + impl<'l, 's> LineBreakType<'l, 's> for LineBreakTypePotentiallyIllFormedUtf8 { type IterAttr = Utf8CharIndices<'s>; type CharType = char; @@ -1181,6 +1194,7 @@ where #[derive(Debug)] pub struct LineBreakTypeLatin1; +impl crate::private::Sealed for LineBreakTypeLatin1 {} impl<'s> LineBreakType<'_, 's> for LineBreakTypeLatin1 { type IterAttr = Latin1Indices<'s>; @@ -1211,6 +1225,7 @@ impl<'s> LineBreakType<'_, 's> for LineBreakTypeLatin1 { #[derive(Debug)] pub struct LineBreakTypeUtf16; +impl crate::private::Sealed for LineBreakTypeUtf16 {} impl<'s> LineBreakType<'_, 's> for LineBreakTypeUtf16 { type IterAttr = Utf16Indices<'s>; diff --git a/components/segmenter/src/rule_segmenter.rs b/components/segmenter/src/rule_segmenter.rs index ad9923ef886..09ee3b512d3 100644 --- a/components/segmenter/src/rule_segmenter.rs +++ b/components/segmenter/src/rule_segmenter.rs @@ -11,15 +11,22 @@ use utf8_iter::Utf8CharIndices; /// A trait allowing for RuleBreakIterator to be generalized to multiple string /// encoding methods and granularity such as grapheme cluster, word, etc. -pub trait RuleBreakType<'l, 's> { +/// +///
+/// 🚫 This trait is sealed; it cannot be implemented by user code. If an API requests an item that implements this +/// trait, please consider using a type from the implementors listed below. +///
+pub trait RuleBreakType<'l, 's>: crate::private::Sealed { /// The iterator over characters. type IterAttr: Iterator + Clone + core::fmt::Debug; /// The character type. type CharType: Copy + Into + core::fmt::Debug; + #[doc(hidden)] fn get_current_position_character_len(iter: &RuleBreakIterator<'l, 's, Self>) -> usize; + #[doc(hidden)] fn handle_complex_language( iter: &mut RuleBreakIterator<'l, 's, Self>, left_codepoint: Self::CharType, @@ -258,6 +265,8 @@ impl<'l, 's, Y: RuleBreakType<'l, 's> + ?Sized> RuleBreakIterator<'l, 's, Y> { #[derive(Debug)] pub struct RuleBreakTypeUtf8; +impl crate::private::Sealed for RuleBreakTypeUtf8 {} + impl<'s> RuleBreakType<'_, 's> for RuleBreakTypeUtf8 { type IterAttr = CharIndices<'s>; type CharType = char; @@ -277,6 +286,8 @@ impl<'s> RuleBreakType<'_, 's> for RuleBreakTypeUtf8 { #[derive(Debug)] pub struct RuleBreakTypePotentiallyIllFormedUtf8; +impl crate::private::Sealed for RuleBreakTypePotentiallyIllFormedUtf8 {} + impl<'s> RuleBreakType<'_, 's> for RuleBreakTypePotentiallyIllFormedUtf8 { type IterAttr = Utf8CharIndices<'s>; type CharType = char; @@ -296,6 +307,8 @@ impl<'s> RuleBreakType<'_, 's> for RuleBreakTypePotentiallyIllFormedUtf8 { #[derive(Debug)] pub struct RuleBreakTypeLatin1; +impl crate::private::Sealed for RuleBreakTypeLatin1 {} + impl<'s> RuleBreakType<'_, 's> for RuleBreakTypeLatin1 { type IterAttr = Latin1Indices<'s>; type CharType = u8; @@ -315,6 +328,8 @@ impl<'s> RuleBreakType<'_, 's> for RuleBreakTypeLatin1 { #[derive(Debug)] pub struct RuleBreakTypeUtf16; +impl crate::private::Sealed for RuleBreakTypeUtf16 {} + impl<'s> RuleBreakType<'_, 's> for RuleBreakTypeUtf16 { type IterAttr = Utf16Indices<'s>; type CharType = u32; diff --git a/components/segmenter/src/word.rs b/components/segmenter/src/word.rs index 695c6994cdc..a35a8493865 100644 --- a/components/segmenter/src/word.rs +++ b/components/segmenter/src/word.rs @@ -546,6 +546,7 @@ impl WordSegmenter { #[derive(Debug)] pub struct WordBreakTypeUtf8; +impl crate::private::Sealed for WordBreakTypeUtf8 {} impl<'l, 's> RuleBreakType<'l, 's> for WordBreakTypeUtf8 { type IterAttr = CharIndices<'s>; @@ -565,6 +566,7 @@ impl<'l, 's> RuleBreakType<'l, 's> for WordBreakTypeUtf8 { #[derive(Debug)] pub struct WordBreakTypePotentiallyIllFormedUtf8; +impl crate::private::Sealed for WordBreakTypePotentiallyIllFormedUtf8 {} impl<'l, 's> RuleBreakType<'l, 's> for WordBreakTypePotentiallyIllFormedUtf8 { type IterAttr = Utf8CharIndices<'s>; @@ -640,6 +642,8 @@ where #[derive(Debug)] pub struct WordBreakTypeUtf16; +impl crate::private::Sealed for WordBreakTypeUtf16 {} + impl<'s> RuleBreakType<'_, 's> for WordBreakTypeUtf16 { type IterAttr = Utf16Indices<'s>; type CharType = u32; diff --git a/components/timezone/src/time_zone.rs b/components/timezone/src/time_zone.rs index 5050d26e777..039e5409ed4 100644 --- a/components/timezone/src/time_zone.rs +++ b/components/timezone/src/time_zone.rs @@ -12,6 +12,11 @@ mod private { } /// Trait encoding a particular data model for time zones. +/// +///
+/// 🚫 This trait is sealed; it cannot be implemented by user code. If an API requests an item that implements this +/// trait, please consider using a type from the implementors listed below. +///
pub trait TimeZoneModel: private::Sealed { /// The zone variant, if required for this time zone model. type ZoneVariant: IntoOption + fmt::Debug + Copy;