From fa9a209b003b0b615bb434e28c1c5bf537162031 Mon Sep 17 00:00:00 2001 From: Patrick Elsen Date: Wed, 7 Feb 2024 23:16:23 +0100 Subject: [PATCH] Various fixes - Removes clippy warning about needless borrow - Changes to using non-deprecated chrono function in example - Switches to using `From<[T]>` implementation for macro - Tests empty macro invocation --- examples/roster.rs | 2 +- src/inclusive_map.rs | 3 ++- src/inclusive_set.rs | 3 ++- src/map.rs | 3 ++- src/operations.rs | 2 +- src/set.rs | 3 ++- 6 files changed, 10 insertions(+), 6 deletions(-) diff --git a/examples/roster.rs b/examples/roster.rs index 2bde449..cba17db 100644 --- a/examples/roster.rs +++ b/examples/roster.rs @@ -7,7 +7,7 @@ fn main() { let mut roster = RangeMap::new(); // Set up initial roster. - let start_of_roster = Utc.ymd(2019, 1, 7); + let start_of_roster = Utc.with_ymd_and_hms(2019, 1, 7, 0, 0, 0).unwrap(); let mut week_start = start_of_roster; for _ in 0..3 { for person in &people { diff --git a/src/inclusive_map.rs b/src/inclusive_map.rs index 0e60b1b..752da0a 100644 --- a/src/inclusive_map.rs +++ b/src/inclusive_map.rs @@ -931,7 +931,7 @@ impl From<[(RangeInclu #[macro_export] macro_rules! range_inclusive_map { ($($k:expr => $v:expr),* $(,)?) => {{ - <$crate::RangeInclusiveMap<_, _> as core::iter::FromIterator<_>>::from_iter([$(($k, $v),)*]) + $crate::RangeInclusiveMap::from([$(($k, $v)),*]) }}; } @@ -1039,6 +1039,7 @@ mod tests { #[test] fn test_macro() { + assert_eq!(range_inclusive_map![], RangeInclusiveMap::::new()); assert_eq!( range_inclusive_map!(0..=100 => "abc", 100..=200 => "def", 200..=300 => "ghi"), [(0..=100, "abc"), (100..=200, "def"), (200..=300, "ghi")] diff --git a/src/inclusive_set.rs b/src/inclusive_set.rs index c98c978..e82e320 100644 --- a/src/inclusive_set.rs +++ b/src/inclusive_set.rs @@ -449,7 +449,7 @@ impl From<[RangeInclusive; N]> #[macro_export] macro_rules! range_inclusive_set { ($($range:expr),* $(,)?) => {{ - <$crate::RangeInclusiveSet<_> as core::iter::FromIterator<_>>::from_iter([$($range,)*]) + $crate::RangeInclusiveSet::from([$($range),*]) }}; } @@ -561,6 +561,7 @@ mod tests { #[test] fn test_macro() { + assert_eq!(range_inclusive_set![], RangeInclusiveSet::::new()); assert_eq!( range_inclusive_set![0..=100, 200..=300, 400..=500], [0..=100, 200..=300, 400..=500].iter().cloned().collect(), diff --git a/src/map.rs b/src/map.rs index 8964992..a160962 100644 --- a/src/map.rs +++ b/src/map.rs @@ -819,7 +819,7 @@ impl From<[(Range, V); N]> for #[macro_export] macro_rules! range_map { ($($k:expr => $v:expr),* $(,)?) => {{ - <$crate::RangeMap<_, _> as core::iter::FromIterator<_>>::from_iter([$(($k, $v),)*]) + $crate::RangeMap::from([$(($k, $v)),*]) }}; } @@ -924,6 +924,7 @@ mod tests { #[test] fn test_macro() { + assert_eq!(range_map![], RangeMap::::new()); assert_eq!( range_map!(0..100 => "abc", 100..200 => "def", 200..300 => "ghi"), [(0..100, "abc"), (100..200, "def"), (200..300, "ghi")] diff --git a/src/operations.rs b/src/operations.rs index c5cb5ac..1a4c373 100644 --- a/src/operations.rs +++ b/src/operations.rs @@ -27,7 +27,7 @@ impl RangeOrder for RangeInclusive { } fn order_end(&self, other: &Self) -> Ordering { - self.end().cmp(&other.end()) + self.end().cmp(other.end()) } } diff --git a/src/set.rs b/src/set.rs index 99fc0f0..874379c 100644 --- a/src/set.rs +++ b/src/set.rs @@ -431,7 +431,7 @@ impl From<[Range; N]> for RangeSet { #[macro_export] macro_rules! range_set { ($($range:expr),* $(,)?) => {{ - <$crate::RangeSet<_> as core::iter::FromIterator<_>>::from_iter([$($range,)*]) + $crate::RangeSet::from([$($range),*]) }}; } @@ -525,6 +525,7 @@ mod tests { #[test] fn test_macro() { + assert_eq!(range_set![], RangeSet::::new()); assert_eq!( range_set![0..100, 200..300, 400..500], [0..100, 200..300, 400..500].iter().cloned().collect(),