Skip to content

Commit

Permalink
rm NeverCalendar
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc committed Oct 15, 2024
1 parent 2a3df7e commit f3c702c
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 36 deletions.
12 changes: 2 additions & 10 deletions components/datetime/src/calendar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,7 @@ pub trait CldrCalendar: InternalCldrCalendar {
type SkeletaV1Marker: DataMarker<DataStruct = PackedPatternsV1<'static>>;
}

/// A calendar that can never exist.
///
/// Used as a substitute for calendar parameters when a calendar is not needed,
/// such as in a time formatter.
#[derive(Debug)]
#[allow(clippy::exhaustive_enums)] // empty enum
pub enum NeverCalendar {}

impl CldrCalendar for NeverCalendar {
impl CldrCalendar for () {
type YearNamesV1Marker = NeverMarker<YearNamesV1<'static>>;
type MonthNamesV1Marker = NeverMarker<MonthNamesV1<'static>>;
type SkeletaV1Marker = NeverMarker<PackedPatternsV1<'static>>;
Expand Down Expand Up @@ -163,7 +155,7 @@ impl CldrCalendar for Roc {
type SkeletaV1Marker = RocDateNeoSkeletonPatternsV1Marker;
}

impl InternalCldrCalendar for NeverCalendar {}
impl InternalCldrCalendar for () {}
impl InternalCldrCalendar for Buddhist {}
impl InternalCldrCalendar for Chinese {}
impl InternalCldrCalendar for Coptic {}
Expand Down
3 changes: 1 addition & 2 deletions components/datetime/src/format/neo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1413,15 +1413,14 @@ impl<C: CldrCalendar, R: DateTimeNamesMarker> TypedDateTimeNames<C, R> {
/// ```
/// use icu::calendar::Time;
/// use icu::datetime::neo_pattern::DateTimePattern;
/// use icu::datetime::NeverCalendar;
/// use icu::datetime::TypedDateTimeNames;
/// use icu::datetime::neo_skeleton::NeoTimeSkeleton;
/// use icu::locale::locale;
/// use writeable::assert_try_writeable_eq;
///
/// let locale = &locale!("bn").into();
///
/// let mut names = TypedDateTimeNames::<NeverCalendar, NeoTimeSkeleton>::try_new(&locale).unwrap();
/// let mut names = TypedDateTimeNames::<(), NeoTimeSkeleton>::try_new(&locale).unwrap();
/// names.include_fixed_decimal_formatter();
///
/// // Create a pattern for the time, which is all numbers
Expand Down
2 changes: 1 addition & 1 deletion components/datetime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ mod time_zone;
mod tz_registry;

pub use calendar::CldrCalendar;
pub use calendar::{InternalCldrCalendar, NeverCalendar};
pub use calendar::InternalCldrCalendar;
pub use error::MismatchedCalendarError;
pub use format::datetime::DateTimeWriteError;
pub use format::neo::{FormattedDateTimePattern, LoadError, SingleLoadError, TypedDateTimeNames};
Expand Down
20 changes: 8 additions & 12 deletions components/datetime/src/neo_marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,13 @@
//! use icu::datetime::neo::TypedNeoFormatter;
//! use icu::datetime::neo_marker::NeoHourMinuteMarker;
//! use icu::datetime::neo_skeleton::NeoSkeletonLength;
//! use icu::datetime::NeverCalendar;
//! use icu::locale::locale;
//! use writeable::assert_try_writeable_eq;
//!
//! // By default, en-US uses 12-hour time and fr-FR uses 24-hour time,
//! // but we can set overrides.
//!
//! let formatter = TypedNeoFormatter::<NeverCalendar, _>::try_new(
//! let formatter = TypedNeoFormatter::<(), _>::try_new(
//! &locale!("en-US-u-hc-h12").into(),
//! NeoHourMinuteMarker::with_length(NeoSkeletonLength::Short),
//! )
Expand All @@ -172,7 +171,7 @@
//! "4:12 PM"
//! );
//!
//! let formatter = TypedNeoFormatter::<NeverCalendar, _>::try_new(
//! let formatter = TypedNeoFormatter::<(), _>::try_new(
//! &locale!("en-US-u-hc-h23").into(),
//! NeoHourMinuteMarker::with_length(NeoSkeletonLength::Short),
//! )
Expand All @@ -182,7 +181,7 @@
//! "16:12"
//! );
//!
//! let formatter = TypedNeoFormatter::<NeverCalendar, _>::try_new(
//! let formatter = TypedNeoFormatter::<(), _>::try_new(
//! &locale!("fr-FR-u-hc-h12").into(),
//! NeoHourMinuteMarker::with_length(NeoSkeletonLength::Short),
//! )
Expand All @@ -192,7 +191,7 @@
//! "4:12 PM"
//! );
//!
//! let formatter = TypedNeoFormatter::<NeverCalendar, _>::try_new(
//! let formatter = TypedNeoFormatter::<(), _>::try_new(
//! &locale!("fr-FR-u-hc-h23").into(),
//! NeoHourMinuteMarker::with_length(NeoSkeletonLength::Short),
//! )
Expand All @@ -210,11 +209,10 @@
//! use icu::datetime::neo::TypedNeoFormatter;
//! use icu::datetime::neo_marker::NeoHourMinuteMarker;
//! use icu::datetime::neo_skeleton::NeoSkeletonLength;
//! use icu::datetime::NeverCalendar;
//! use icu::locale::locale;
//! use writeable::assert_try_writeable_eq;
//!
//! let formatter = TypedNeoFormatter::<NeverCalendar, _>::try_new(
//! let formatter = TypedNeoFormatter::<(), _>::try_new(
//! &locale!("und-u-hc-h11").into(),
//! NeoHourMinuteMarker::with_length(NeoSkeletonLength::Short),
//! )
Expand All @@ -224,7 +222,7 @@
//! "0:00 AM"
//! );
//!
//! let formatter = TypedNeoFormatter::<NeverCalendar, _>::try_new(
//! let formatter = TypedNeoFormatter::<(), _>::try_new(
//! &locale!("und-u-hc-h24").into(),
//! NeoHourMinuteMarker::with_length(NeoSkeletonLength::Short),
//! )
Expand All @@ -246,11 +244,10 @@
//! use icu::datetime::neo_marker::NeoHourMinuteSecondMarker;
//! use icu::datetime::neo_skeleton::FractionalSecondDigits;
//! use icu::datetime::neo_skeleton::NeoSkeletonLength;
//! use icu::datetime::NeverCalendar;
//! use icu::locale::locale;
//! use writeable::assert_try_writeable_eq;
//!
//! let formatter = TypedNeoFormatter::<NeverCalendar, _>::try_new(
//! let formatter = TypedNeoFormatter::<(), _>::try_new(
//! &locale!("en-US").into(),
//! NeoHourMinuteSecondMarker::with_length(NeoSkeletonLength::Short)
//! .with_fractional_second_digits(FractionalSecondDigits::F2),
Expand All @@ -274,7 +271,6 @@
//! use icu::datetime::neo::TypedNeoFormatter;
//! use icu::datetime::neo_marker::NeoTimeZoneGenericMarker;
//! use icu::datetime::neo_skeleton::NeoSkeletonLength;
//! use icu::datetime::NeverCalendar;
//! use icu::datetime::DateTimeWriteError;
//! use icu::locale::locale;
//! use tinystr::tinystr;
Expand All @@ -294,7 +290,7 @@
//! .unwrap();
//!
//! // Set up the formatter
//! let mut tzf = TypedNeoFormatter::<NeverCalendar, _>::try_new(
//! let mut tzf = TypedNeoFormatter::<(), _>::try_new(
//! &locale!("en").into(),
//! NeoTimeZoneGenericMarker::with_length(NeoSkeletonLength::Short),
//! )
Expand Down
9 changes: 3 additions & 6 deletions components/datetime/tests/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,12 +475,10 @@ fn test_time_zone_format_configs() {

#[test]
fn test_time_zone_format_offset_seconds() {
use icu_datetime::{
neo_marker::NeoTimeZoneOffsetMarker, neo_skeleton::NeoSkeletonLength, NeverCalendar,
};
use icu_datetime::{neo_marker::NeoTimeZoneOffsetMarker, neo_skeleton::NeoSkeletonLength};

let time_zone = CustomTimeZone::new_with_offset(UtcOffset::try_from_seconds(12).unwrap());
let tzf = TypedNeoFormatter::<NeverCalendar, _>::try_new(
let tzf = TypedNeoFormatter::<(), _>::try_new(
&locale!("en").into(),
NeoTimeZoneOffsetMarker::with_length(NeoSkeletonLength::Medium),
)
Expand All @@ -492,11 +490,10 @@ fn test_time_zone_format_offset_seconds() {
fn test_time_zone_format_offset_not_set_debug_assert_panic() {
use icu_datetime::{
neo_marker::NeoTimeZoneOffsetMarker, neo_skeleton::NeoSkeletonLength, DateTimeWriteError,
NeverCalendar,
};

let time_zone = CustomTimeZone::try_from_str("America/Los_Angeles").unwrap();
let tzf = TypedNeoFormatter::<NeverCalendar, _>::try_new(
let tzf = TypedNeoFormatter::<(), _>::try_new(
&locale!("en").into(),
NeoTimeZoneOffsetMarker::with_length(NeoSkeletonLength::Medium),
)
Expand Down
5 changes: 1 addition & 4 deletions ffi/capi/src/datetime_formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ pub mod ffi {
use icu_datetime::{
neo_marker::{NeoHourMinuteMarker, NeoYearMonthDayHourMinuteMarker, NeoYearMonthDayMarker},
neo_skeleton::NeoSkeletonLength,
NeverCalendar,
};

use crate::{
Expand All @@ -27,9 +26,7 @@ pub mod ffi {
#[diplomat::opaque]
/// An ICU4X TimeFormatter object capable of formatting an [`Time`] type (and others) as a string
#[diplomat::rust_link(icu::datetime, Mod)]
pub struct TimeFormatter(
pub icu_datetime::neo::TypedNeoFormatter<NeverCalendar, NeoHourMinuteMarker>,
);
pub struct TimeFormatter(pub icu_datetime::neo::TypedNeoFormatter<(), NeoHourMinuteMarker>);

#[diplomat::enum_convert(icu_datetime::neo_skeleton::NeoSkeletonLength, needs_wildcard)]
#[diplomat::rust_link(icu::datetime::neo_skeleton::NeoSkeletonLength, Enum)]
Expand Down
1 change: 0 additions & 1 deletion tools/make/diplomat-coverage/src/allowlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,6 @@ lazy_static::lazy_static! {
"icu::calendar::gregorian::Gregorian",
"icu::calendar::gregorian::GregorianDateInner",
"icu::calendar::any_calendar::AnyDateInner",
"icu::datetime::NeverCalendar",

// Options bags which are expanded in FFI to regular functions
// TODO-2.0: investigate flattening on the rust side too
Expand Down

0 comments on commit f3c702c

Please sign in to comment.