From 731ba9d54a99a9b7e3ddd100c10491db97304e74 Mon Sep 17 00:00:00 2001 From: Eugene Lomov Date: Mon, 5 Jun 2023 13:22:53 +0300 Subject: [PATCH 1/2] Added Ord and Eq traits for types, which already derives PartialOrd and PartialEq --- src/month.rs | 4 ++-- src/naive/date.rs | 2 +- src/naive/internals.rs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/month.rs b/src/month.rs index 11df7613dd..4c6321e152 100644 --- a/src/month.rs +++ b/src/month.rs @@ -28,7 +28,7 @@ use crate::OutOfRange; /// Allows mapping from and to month, from 1-January to 12-December. /// Can be Serialized/Deserialized with serde // Actual implementation is zero-indexed, API intended as 1-indexed for more intuitive behavior. -#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash, PartialOrd)] +#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash, PartialOrd, Ord)] #[cfg_attr(feature = "rustc-serialize", derive(RustcEncodable, RustcDecodable))] #[cfg_attr(feature = "rkyv", derive(Archive, Deserialize, Serialize))] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] @@ -218,7 +218,7 @@ impl num_traits::FromPrimitive for Month { } /// A duration in calendar months -#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd)] +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] pub struct Months(pub(crate) u32); diff --git a/src/naive/date.rs b/src/naive/date.rs index b9404a15f5..6ad560b9e0 100644 --- a/src/naive/date.rs +++ b/src/naive/date.rs @@ -137,7 +137,7 @@ impl NaiveWeek { /// that adding `Duration::days(1)` doesn't increment the day value as expected due to it being a /// fixed number of seconds. This difference applies only when dealing with `DateTime` data types /// and in other cases `Duration::days(n)` and `Days::new(n)` are equivalent. -#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd)] +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] pub struct Days(pub(crate) u64); impl Days { diff --git a/src/naive/internals.rs b/src/naive/internals.rs index 65b47ae73b..0020178c6b 100644 --- a/src/naive/internals.rs +++ b/src/naive/internals.rs @@ -268,7 +268,7 @@ const OL_TO_MDL: &[u8; MAX_OL as usize + 1] = &[ /// which is an index to the `OL_TO_MDL` lookup table. /// /// The methods implemented on `Of` always return a valid value. -#[derive(PartialEq, PartialOrd, Copy, Clone)] +#[derive(PartialEq, PartialOrd, Copy, Clone, Ord, Eq)] pub(super) struct Of(u32); impl Of { @@ -391,7 +391,7 @@ impl fmt::Debug for Of { /// The methods implemented on `Mdf` do not always return a valid value. /// Dates that can't exist, like February 30, can still be represented. /// Use `Mdl::valid` to check whether the date is valid. -#[derive(PartialEq, PartialOrd, Copy, Clone)] +#[derive(PartialEq, PartialOrd, Copy, Clone, Ord, Eq)] pub(super) struct Mdf(u32); impl Mdf { From 5526de35c6d7621ba90cb9a049d36bc711662c98 Mon Sep 17 00:00:00 2001 From: Eugene Lomov Date: Mon, 5 Jun 2023 15:27:27 +0300 Subject: [PATCH 2/2] Removed Ord and Eq traits for private types --- src/naive/internals.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/naive/internals.rs b/src/naive/internals.rs index 0020178c6b..65b47ae73b 100644 --- a/src/naive/internals.rs +++ b/src/naive/internals.rs @@ -268,7 +268,7 @@ const OL_TO_MDL: &[u8; MAX_OL as usize + 1] = &[ /// which is an index to the `OL_TO_MDL` lookup table. /// /// The methods implemented on `Of` always return a valid value. -#[derive(PartialEq, PartialOrd, Copy, Clone, Ord, Eq)] +#[derive(PartialEq, PartialOrd, Copy, Clone)] pub(super) struct Of(u32); impl Of { @@ -391,7 +391,7 @@ impl fmt::Debug for Of { /// The methods implemented on `Mdf` do not always return a valid value. /// Dates that can't exist, like February 30, can still be represented. /// Use `Mdl::valid` to check whether the date is valid. -#[derive(PartialEq, PartialOrd, Copy, Clone, Ord, Eq)] +#[derive(PartialEq, PartialOrd, Copy, Clone)] pub(super) struct Mdf(u32); impl Mdf {