Skip to content

Commit

Permalink
Move pattern and skeleton modules to provider (#5744)
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc authored Oct 30, 2024
1 parent 8344161 commit 67a3904
Show file tree
Hide file tree
Showing 47 changed files with 273 additions and 355 deletions.
2 changes: 1 addition & 1 deletion components/datetime/benches/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod fixtures;

use criterion::{criterion_group, criterion_main, Criterion};

use icu_datetime::pattern::reference::Pattern;
use icu_datetime::provider::pattern::reference::Pattern;

fn pattern_benches(c: &mut Criterion) {
let patterns = serde_json::from_str::<fixtures::PatternsFixture>(include_str!(
Expand Down
6 changes: 3 additions & 3 deletions components/datetime/src/format/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use super::{
};
use crate::fields::{self, Day, Field, FieldLength, FieldSymbol, Second, Week, Year};
use crate::input::ExtractedInput;
use crate::pattern::runtime::PatternMetadata;
use crate::pattern::PatternItem;
use crate::provider::pattern::runtime::PatternMetadata;
use crate::provider::pattern::PatternItem;
use crate::time_zone::{
FormatTimeZone, FormatTimeZoneError, Iso8601Format, IsoFormat, IsoMinutes, IsoSeconds,
ResolvedNeoTimeZoneSkeleton,
Expand Down Expand Up @@ -556,7 +556,7 @@ where
#[cfg(feature = "compiled_data")]
mod tests {
use super::*;
use crate::{fieldset::YMD, neo_skeleton::NeoSkeletonLength, pattern::runtime};
use crate::{fieldset::YMD, neo_skeleton::NeoSkeletonLength, provider::pattern::runtime};
use icu_calendar::types::FormattingEra;
use icu_decimal::options::{FixedDecimalFormatterOptions, GroupingStrategy};
use tinystr::tinystr;
Expand Down
2 changes: 1 addition & 1 deletion components/datetime/src/format/neo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use crate::input;
use crate::input::ExtractedInput;
use crate::neo_pattern::{DateTimePattern, DateTimePatternBorrowed};
use crate::neo_skeleton::NeoDateTimeSkeleton;
use crate::pattern::PatternItem;
use crate::provider::neo::*;
use crate::provider::pattern::PatternItem;
use crate::provider::time_zones::tz;
use crate::scaffold::*;
use crate::scaffold::{
Expand Down
6 changes: 0 additions & 6 deletions components/datetime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,9 @@ pub mod neo_pattern;
mod neo_serde;
pub mod neo_skeleton;
pub mod options;
#[doc(hidden)]
pub mod pattern;
pub mod provider;
pub(crate) mod raw;
pub mod scaffold;
#[doc(hidden)]
#[allow(clippy::exhaustive_structs, clippy::exhaustive_enums)] // private-ish module
#[cfg(feature = "datagen")]
pub mod skeleton;
mod time_zone;
mod tz_registry;

Expand Down
7 changes: 4 additions & 3 deletions components/datetime/src/neo_pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ use core::str::FromStr;
use writeable::{impl_display_with_writeable, Writeable};

use crate::helpers::size_test;
use crate::pattern::{runtime, PatternError, PatternItem};
use crate::provider::pattern::{runtime, PatternError, PatternItem};

size_test!(DateTimePattern, date_time_pattern_size, 32);

/// A pattern for formatting a datetime in a calendar.
///
/// Most clients should use [`DateTimeFormatter`](crate::neo::DateTimeFormatter) instead of directly
/// formatting with patterns.
/// [`DateTimePattern`] forgoes most internationalization functionality of the datetime crate.
/// It assumes that the pattern is already localized for the customer's locale. Most clients
/// should use [`DateTimeFormatter`] instead of directly formatting with patterns.
///
/// There are two ways to make one of these:
///
Expand Down
2 changes: 1 addition & 1 deletion components/datetime/src/neo_skeleton.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use crate::neo_serde::*;
#[cfg(feature = "datagen")]
use crate::options::{self, length};
use crate::pattern::CoarseHourCycle;
use crate::provider::pattern::CoarseHourCycle;
use crate::time_zone::ResolvedNeoTimeZoneSkeleton;
use icu_provider::DataMarkerAttributes;
use icu_timezone::scaffold::IntoOption;
Expand Down
6 changes: 2 additions & 4 deletions components/datetime/src/options/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,8 @@
use crate::{
fields::{self, Field, FieldLength, FieldSymbol},
neo_skeleton::FractionalSecondDigits,
pattern::{
runtime::{Pattern, PatternPlurals},
PatternItem,
},
provider::pattern::{runtime::Pattern, PatternItem},
provider::skeleton::PatternPlurals,
};

use super::preferences;
Expand Down
22 changes: 0 additions & 22 deletions components/datetime/src/pattern/runtime/mod.rs

This file was deleted.

18 changes: 2 additions & 16 deletions components/datetime/src/provider/calendar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
mod skeletons;
mod symbols;

use crate::pattern;
use crate::provider::pattern;
use icu_provider::prelude::*;
#[cfg(feature = "datagen")]
pub use skeletons::*;
Expand Down Expand Up @@ -89,7 +89,7 @@ pub struct TimeLengthsV1<'data> {
/// and/or plural forms.
pub mod patterns {
use super::*;
use crate::pattern::runtime::{self, GenericPattern, PatternPlurals};
use crate::provider::pattern::runtime::{self, GenericPattern};

/// Data struct for date/time patterns broken down by pattern length.
///
Expand Down Expand Up @@ -143,20 +143,6 @@ pub mod patterns {
pub short: GenericPattern<'data>,
}

#[icu_provider::data_struct]
#[derive(Debug, PartialEq, Clone, Default)]
#[cfg_attr(feature = "datagen", derive(serde::Serialize))]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
pub(crate) struct PatternPluralsV1<'data>(
#[cfg_attr(feature = "serde", serde(borrow))] pub PatternPlurals<'data>,
);

impl<'data> From<PatternPlurals<'data>> for PatternPluralsV1<'data> {
fn from(pattern: PatternPlurals<'data>) -> Self {
Self(pattern)
}
}

/// A general purpose pattern representation. Used for date-time glue patterns.
///
/// Expresses the formatting positions of other formatted elements (ex: the order
Expand Down
5 changes: 1 addition & 4 deletions components/datetime/src/provider/calendar/skeletons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use crate::{
pattern::runtime::PatternPlurals,
skeleton::{reference::Skeleton, SkeletonError},
};
use crate::provider::skeleton::{reference::Skeleton, PatternPlurals, SkeletonError};
use core::convert::TryFrom;
use litemap::LiteMap;

Expand Down
3 changes: 3 additions & 0 deletions components/datetime/src/provider/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
pub mod calendar;
pub mod neo;
pub(crate) mod packed_pattern;
pub mod pattern;
#[cfg(feature = "datagen")]
pub mod skeleton;
pub mod time_zones;

pub use packed_pattern::*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
mod adapter;

use crate::pattern::runtime::{self, PatternULE};
use crate::provider::pattern::runtime::{self, PatternULE};
use alloc::borrow::Cow;
use core::ops::Range;
use icu_provider::prelude::*;
Expand Down
16 changes: 6 additions & 10 deletions components/datetime/src/provider/packed_pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@

//! Data structures for packing of datetime patterns.
use crate::pattern::runtime::Pattern;
use crate::{
helpers::size_test,
pattern::{
runtime::{PatternBorrowed, PatternMetadata},
PatternItem,
},
NeoSkeletonLength,
use super::pattern::{
runtime::{Pattern, PatternBorrowed, PatternMetadata},
PatternItem,
};
use crate::{helpers::size_test, NeoSkeletonLength};
use alloc::vec::Vec;
use icu_plurals::{
provider::{FourBitMetadata, PluralElementsPackedULE},
Expand Down Expand Up @@ -521,7 +517,7 @@ impl PackedPatternsV1<'_> {
#[cfg(feature = "serde")]
mod _serde {
use super::*;
use crate::pattern::reference;
use crate::provider::pattern::reference;
use zerovec::VarZeroSlice;

#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
Expand Down Expand Up @@ -653,7 +649,7 @@ mod _serde {
#[cfg(test)]
pub mod tests {
use super::*;
use crate::pattern::reference;
use crate::provider::pattern::reference;

const PATTERN_STRS: &[&str] = &[
"M/d/y",
Expand Down
Loading

0 comments on commit 67a3904

Please sign in to comment.