diff --git a/src/inclusive_map.rs b/src/inclusive_map.rs index 15351be..31957e0 100644 --- a/src/inclusive_map.rs +++ b/src/inclusive_map.rs @@ -33,7 +33,7 @@ use serde::{ /// you can provide equivalent free functions using the `StepFnsT` type parameter. /// [`StepLite`](crate::StepLite) is implemented for all standard integer types, /// but not for any third party crate types. -#[derive(Clone)] +#[derive(Clone, Hash, Default)] pub struct RangeInclusiveMap { // Wrap ranges so that they are `Ord`. // See `range_wrapper.rs` for explanation. @@ -41,16 +41,6 @@ pub struct RangeInclusiveMap { _phantom: PhantomData, } -impl Default for RangeInclusiveMap -where - K: Ord + Clone + StepLite, - V: Eq + Clone, -{ - fn default() -> Self { - Self::new() - } -} - impl PartialEq for RangeInclusiveMap where K: PartialEq, diff --git a/src/inclusive_set.rs b/src/inclusive_set.rs index ff99a49..8b6ddfe 100644 --- a/src/inclusive_set.rs +++ b/src/inclusive_set.rs @@ -15,7 +15,7 @@ use serde::{ use crate::std_ext::*; use crate::RangeInclusiveMap; -#[derive(Clone)] +#[derive(Clone, Hash, Default)] /// A set whose items are stored as ranges bounded /// inclusively below and above `(start..=end)`. /// @@ -26,42 +26,33 @@ pub struct RangeInclusiveSet { rm: RangeInclusiveMap, } -impl Default for RangeInclusiveSet -where - T: Ord + Clone + StepLite, -{ - fn default() -> Self { - Self::new() - } -} - -impl PartialEq for RangeInclusiveSet +impl PartialEq for RangeInclusiveSet where T: PartialEq, { - fn eq(&self, other: &RangeInclusiveSet) -> bool { + fn eq(&self, other: &Self) -> bool { self.rm == other.rm } } -impl Eq for RangeInclusiveSet where T: Eq {} +impl Eq for RangeInclusiveSet where T: Eq {} -impl PartialOrd for RangeInclusiveSet +impl PartialOrd for RangeInclusiveSet where T: PartialOrd, { #[inline] - fn partial_cmp(&self, other: &RangeInclusiveSet) -> Option { + fn partial_cmp(&self, other: &Self) -> Option { self.rm.partial_cmp(&other.rm) } } -impl Ord for RangeInclusiveSet +impl Ord for RangeInclusiveSet where T: Ord, { #[inline] - fn cmp(&self, other: &RangeInclusiveSet) -> Ordering { + fn cmp(&self, other: &Self) -> Ordering { self.rm.cmp(&other.rm) } } diff --git a/src/map.rs b/src/map.rs index 761b247..991611c 100644 --- a/src/map.rs +++ b/src/map.rs @@ -22,19 +22,13 @@ use serde::{ /// /// Contiguous and overlapping ranges that map to the same value /// are coalesced into a single range. -#[derive(Clone)] +#[derive(Clone, Hash, Default, Eq)] pub struct RangeMap { // Wrap ranges so that they are `Ord`. // See `range_wrapper.rs` for explanation. pub(crate) btm: BTreeMap, V>, } -impl Default for RangeMap { - fn default() -> Self { - Self::new() - } -} - impl PartialEq for RangeMap where K: PartialEq, @@ -67,13 +61,6 @@ where } } -impl Eq for RangeMap -where - K: Eq, - V: Eq, -{ -} - impl RangeMap { /// Makes a new empty `RangeMap`. #[cfg(feature = "const_fn")] diff --git a/src/range_wrapper.rs b/src/range_wrapper.rs index 0a54ee7..c3804ba 100644 --- a/src/range_wrapper.rs +++ b/src/range_wrapper.rs @@ -32,7 +32,7 @@ use core::ops::{Deref, Range, RangeInclusive}; // Range start wrapper // -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Hash)] pub struct RangeStartWrapper { pub end_wrapper: RangeEndWrapper, } @@ -94,7 +94,7 @@ impl Deref for RangeStartWrapper { // Range end wrapper // -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Hash)] pub struct RangeEndWrapper { pub range: Range, } @@ -148,7 +148,7 @@ impl Deref for RangeEndWrapper { // RangeInclusive start wrapper // -#[derive(Eq, Debug, Clone)] +#[derive(Eq, Debug, Clone, Hash)] pub struct RangeInclusiveStartWrapper { pub end_wrapper: RangeInclusiveEndWrapper, } @@ -208,7 +208,7 @@ impl Deref for RangeInclusiveStartWrapper { // RangeInclusive end wrapper // -#[derive(Eq, Debug, Clone)] +#[derive(Eq, Debug, Clone, Hash)] pub struct RangeInclusiveEndWrapper { pub range: RangeInclusive, } diff --git a/src/set.rs b/src/set.rs index e375244..ee2976f 100644 --- a/src/set.rs +++ b/src/set.rs @@ -1,5 +1,4 @@ use core::borrow::Borrow; -use core::cmp::Ordering; use core::fmt::{self, Debug}; use core::iter::FromIterator; use core::ops::Range; @@ -15,7 +14,7 @@ use serde::{ use crate::RangeMap; -#[derive(Clone)] +#[derive(Clone, Hash, Default, Eq, PartialEq, PartialOrd, Ord)] /// A set whose items are stored as (half-open) ranges bounded /// inclusively below and exclusively above `(start..end)`. /// @@ -26,46 +25,6 @@ pub struct RangeSet { rm: RangeMap, } -impl Default for RangeSet -where - T: Ord + Clone, -{ - fn default() -> Self { - RangeSet::new() - } -} - -impl PartialEq for RangeSet -where - T: PartialEq, -{ - fn eq(&self, other: &RangeSet) -> bool { - self.rm == other.rm - } -} - -impl Eq for RangeSet where T: Eq {} - -impl PartialOrd for RangeSet -where - T: PartialOrd, -{ - #[inline] - fn partial_cmp(&self, other: &RangeSet) -> Option { - self.rm.partial_cmp(&other.rm) - } -} - -impl Ord for RangeSet -where - T: Ord, -{ - #[inline] - fn cmp(&self, other: &RangeSet) -> Ordering { - self.rm.cmp(&other.rm) - } -} - impl RangeSet where T: Ord + Clone,