From 9f4a1b094652b13f531c27ed25b14ef2b6fd65bb Mon Sep 17 00:00:00 2001 From: nekevss Date: Fri, 23 Feb 2024 17:20:37 -0500 Subject: [PATCH] Add non_exhaustive to structs --- src/components/calendar.rs | 2 +- src/components/date.rs | 10 ++-------- src/components/datetime.rs | 1 + src/components/duration.rs | 1 + src/components/duration/date.rs | 3 ++- src/components/duration/time.rs | 1 + src/components/instant.rs | 1 + src/components/month_day.rs | 1 + src/components/time.rs | 1 + src/components/year_month.rs | 1 + src/components/zoneddatetime.rs | 1 + src/iso.rs | 3 +++ 12 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/components/calendar.rs b/src/components/calendar.rs index 04dfac610..ad6b77294 100644 --- a/src/components/calendar.rs +++ b/src/components/calendar.rs @@ -500,7 +500,7 @@ impl CalendarSlot { TemporalUnit::Day, )?; // 10. Let result be ? AddISODate(date.[[ISOYear]], date.[[ISOMonth]], date.[[ISODay]], duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]] + balanceResult.[[Days]], overflow). - let result = date.iso().add_iso_date( + let result = date.iso.add_iso_date( &DateDuration::new_unchecked( duration.days(), duration.months(), diff --git a/src/components/date.rs b/src/components/date.rs index 25da35bce..d1a898bb2 100644 --- a/src/components/date.rs +++ b/src/components/date.rs @@ -21,9 +21,10 @@ use super::{ }; /// The native Rust implementation of `Temporal.PlainDate`. +#[non_exhaustive] #[derive(Debug, Default, Clone)] pub struct Date { - iso: IsoDate, + pub(crate) iso: IsoDate, calendar: CalendarSlot, } @@ -96,13 +97,6 @@ impl Date { self.iso.day } - #[inline] - #[must_use] - /// Returns the `Date`'s inner `IsoDate` record. - pub const fn iso(&self) -> IsoDate { - self.iso - } - #[inline] #[must_use] /// Returns a reference to this `Date`'s calendar slot. diff --git a/src/components/datetime.rs b/src/components/datetime.rs index 1a5197c6f..5936dea9f 100644 --- a/src/components/datetime.rs +++ b/src/components/datetime.rs @@ -17,6 +17,7 @@ use tinystr::TinyAsciiStr; use super::calendar::{CalendarDateLike, GetCalendarSlot}; /// The native Rust implementation of `Temporal.PlainDateTime` +#[non_exhaustive] #[derive(Debug, Default, Clone)] pub struct DateTime { iso: IsoDateTime, diff --git a/src/components/duration.rs b/src/components/duration.rs index bc984700e..edf9b9b6a 100644 --- a/src/components/duration.rs +++ b/src/components/duration.rs @@ -25,6 +25,7 @@ pub use time::TimeDuration; /// /// `Duration` is made up of a `DateDuration` and `TimeDuration` as primarily /// defined by Abtract Operation 7.5.1-5. +#[non_exhaustive] #[derive(Debug, Clone, Copy, Default)] pub struct Duration { date: DateDuration, diff --git a/src/components/duration/date.rs b/src/components/duration/date.rs index 4feb3b35e..bc1cd5f28 100644 --- a/src/components/duration/date.rs +++ b/src/components/duration/date.rs @@ -17,6 +17,7 @@ use super::normalized::NormalizedTimeDuration; /// /// [spec]: https://tc39.es/proposal-temporal/#sec-temporal-date-duration-records /// [field spec]: https://tc39.es/proposal-temporal/#sec-properties-of-temporal-duration-instances +#[non_exhaustive] #[derive(Debug, Default, Clone, Copy)] pub struct DateDuration { pub(crate) years: f64, @@ -254,7 +255,7 @@ impl DateDuration { fractional_days += f64::from(months_weeks_in_days); // k. Let isoResult be ! AddISODate(plainRelativeTo.[[ISOYear]]. plainRelativeTo.[[ISOMonth]], plainRelativeTo.[[ISODay]], 0, 0, 0, truncate(fractionalDays), "constrain"). - let iso_result = plain_relative_to.iso().add_iso_date( + let iso_result = plain_relative_to.iso.add_iso_date( &DateDuration::new_unchecked(0.0, 0.0, 0.0, fractional_days.trunc()), ArithmeticOverflow::Constrain, )?; diff --git a/src/components/duration/time.rs b/src/components/duration/time.rs index 5941fce86..c267090c1 100644 --- a/src/components/duration/time.rs +++ b/src/components/duration/time.rs @@ -17,6 +17,7 @@ const NANOSECONDS_PER_HOUR: u64 = NANOSECONDS_PER_MINUTE * 60; /// /// [spec]: https://tc39.es/proposal-temporal/#sec-temporal-time-duration-records /// [field spec]: https://tc39.es/proposal-temporal/#sec-properties-of-temporal-duration-instances +#[non_exhaustive] #[derive(Debug, Default, Clone, Copy)] pub struct TimeDuration { pub(crate) hours: f64, diff --git a/src/components/instant.rs b/src/components/instant.rs index 76d710a60..097f63e1c 100644 --- a/src/components/instant.rs +++ b/src/components/instant.rs @@ -14,6 +14,7 @@ const NANOSECONDS_PER_MINUTE: f64 = 60f64 * NANOSECONDS_PER_SECOND; const NANOSECONDS_PER_HOUR: f64 = 60f64 * NANOSECONDS_PER_MINUTE; /// The native Rust implementation of `Temporal.Instant` +#[non_exhaustive] #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] pub struct Instant { pub(crate) nanos: BigInt, diff --git a/src/components/month_day.rs b/src/components/month_day.rs index 92a64de00..16e39034c 100644 --- a/src/components/month_day.rs +++ b/src/components/month_day.rs @@ -12,6 +12,7 @@ use crate::{ use super::calendar::{CalendarProtocol, GetCalendarSlot}; /// The native Rust implementation of `Temporal.PlainMonthDay` +#[non_exhaustive] #[derive(Debug, Default, Clone)] pub struct MonthDay { iso: IsoDate, diff --git a/src/components/time.rs b/src/components/time.rs index 5bc909045..142abd67e 100644 --- a/src/components/time.rs +++ b/src/components/time.rs @@ -8,6 +8,7 @@ use crate::{ }; /// The native Rust implementation of `Temporal.PlainTime`. +#[non_exhaustive] #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] pub struct Time { iso: IsoTime, diff --git a/src/components/year_month.rs b/src/components/year_month.rs index 9686c784e..2292e1485 100644 --- a/src/components/year_month.rs +++ b/src/components/year_month.rs @@ -12,6 +12,7 @@ use crate::{ use super::calendar::{CalendarProtocol, GetCalendarSlot}; /// The native Rust implementation of `Temporal.YearMonth`. +#[non_exhaustive] #[derive(Debug, Default, Clone)] pub struct YearMonth { iso: IsoDate, diff --git a/src/components/zoneddatetime.rs b/src/components/zoneddatetime.rs index 04d72941a..3796414b3 100644 --- a/src/components/zoneddatetime.rs +++ b/src/components/zoneddatetime.rs @@ -15,6 +15,7 @@ use crate::{ use super::tz::TzProtocol; /// The native Rust implementation of `Temporal.ZonedDateTime`. +#[non_exhaustive] #[derive(Debug, Clone)] pub struct ZonedDateTime { instant: Instant, diff --git a/src/iso.rs b/src/iso.rs index 49ce55ff8..f51bfd8e9 100644 --- a/src/iso.rs +++ b/src/iso.rs @@ -23,6 +23,7 @@ use num_bigint::BigInt; use num_traits::{cast::FromPrimitive, ToPrimitive}; /// `IsoDateTime` is the record of the `IsoDate` and `IsoTime` internal slots. +#[non_exhaustive] #[derive(Debug, Default, Clone, Copy)] pub struct IsoDateTime { date: IsoDate, @@ -141,6 +142,7 @@ pub trait IsoDateSlots { /// /// These fields are used for the `Temporal.PlainDate` object, the /// `Temporal.YearMonth` object, and the `Temporal.MonthDay` object. +#[non_exhaustive] #[derive(Debug, Clone, Copy, Default)] pub struct IsoDate { pub(crate) year: i32, @@ -252,6 +254,7 @@ impl IsoDate { /// An `IsoTime` record that contains `Temporal`'s /// time slots. +#[non_exhaustive] #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] pub struct IsoTime { pub(crate) hour: u8, // 0..=23