diff --git a/src/inclusive_map.rs b/src/inclusive_map.rs index 732decd..34724f6 100644 --- a/src/inclusive_map.rs +++ b/src/inclusive_map.rs @@ -34,7 +34,7 @@ use serde::{ /// you can provide equivalent free functions using the `StepFnsT` type parameter. /// [`StepLite`] is implemented for all standard integer types, /// but not for any third party crate types. -#[derive(Clone, Default)] +#[derive(Clone)] pub struct RangeInclusiveMap { // Wrap ranges so that they are `Ord`. // See `range_wrapper.rs` for explanation. @@ -42,6 +42,15 @@ pub struct RangeInclusiveMap { _phantom: PhantomData, } +impl Default for RangeInclusiveMap { + fn default() -> Self { + Self { + btm: BTreeMap::default(), + _phantom: PhantomData, + } + } +} + impl Hash for RangeInclusiveMap where K: Hash, @@ -1869,6 +1878,14 @@ mod tests { assert_eq!(format!("{:?}", map), "{2..=5: (), 7..=8: (), 10..=11: ()}"); } + // impl Default where T: ?Default + + #[test] + fn always_default() { + struct NoDefault; + RangeInclusiveMap::::default(); + } + // impl Serialize #[cfg(feature = "serde1")] diff --git a/src/inclusive_set.rs b/src/inclusive_set.rs index 1077698..46bb8f7 100644 --- a/src/inclusive_set.rs +++ b/src/inclusive_set.rs @@ -20,7 +20,7 @@ pub type Intersection<'a, T> = crate::operations::Intersection<'a, RangeInclusiv /// Union iterator over two [`RangeInclusiveSet`]. pub type Union<'a, T> = crate::operations::Union<'a, RangeInclusive, Iter<'a, T>>; -#[derive(Clone, Hash, Default, Eq, PartialEq, PartialOrd, Ord)] +#[derive(Clone, Hash, Eq, PartialEq, PartialOrd, Ord)] /// A set whose items are stored as ranges bounded /// inclusively below and above `(start..=end)`. /// @@ -31,6 +31,14 @@ pub struct RangeInclusiveSet { rm: RangeInclusiveMap, } +impl Default for RangeInclusiveSet { + fn default() -> Self { + Self { + rm: RangeInclusiveMap::default(), + } + } +} + impl RangeInclusiveSet where T: Ord + Clone + StepLite, @@ -777,6 +785,14 @@ mod tests { assert_eq!(format!("{:?}", set), "{2..=5, 7..=8, 10..=11}"); } + // impl Default where T: ?Default + + #[test] + fn always_default() { + struct NoDefault; + RangeInclusiveSet::::default(); + } + // impl Serialize #[cfg(feature = "serde1")] diff --git a/src/map.rs b/src/map.rs index f4167a0..d56b274 100644 --- a/src/map.rs +++ b/src/map.rs @@ -23,13 +23,21 @@ use serde::{ /// /// Contiguous and overlapping ranges that map to the same value /// are coalesced into a single range. -#[derive(Clone, Default, Eq)] +#[derive(Clone, 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 { + btm: BTreeMap::default(), + } + } +} + impl Hash for RangeMap where K: Hash, @@ -1702,6 +1710,14 @@ mod tests { assert_eq!(format!("{:?}", map), "{2..5: (), 6..7: (), 8..9: ()}"); } + // impl Default where T: ?Default + + #[test] + fn always_default() { + struct NoDefault; + RangeMap::::default(); + } + // Iterator Tests #[test] diff --git a/src/set.rs b/src/set.rs index a48aa65..549e60d 100644 --- a/src/set.rs +++ b/src/set.rs @@ -20,7 +20,7 @@ pub type Intersection<'a, T> = crate::operations::Intersection<'a, Range, Ite /// Union iterator over two [`RangeSet`]. pub type Union<'a, T> = crate::operations::Union<'a, Range, Iter<'a, T>>; -#[derive(Clone, Hash, Default, Eq, PartialEq, PartialOrd, Ord)] +#[derive(Clone, Hash, Eq, PartialEq, PartialOrd, Ord)] /// A set whose items are stored as (half-open) ranges bounded /// inclusively below and exclusively above `(start..end)`. /// @@ -31,6 +31,14 @@ pub struct RangeSet { rm: RangeMap, } +impl Default for RangeSet { + fn default() -> Self { + Self { + rm: RangeMap::default(), + } + } +} + impl RangeSet where T: Ord + Clone, @@ -746,6 +754,14 @@ mod tests { assert_eq!(format!("{:?}", set), "{2..5, 7..8, 10..11}"); } + // impl Default where T: ?Default + + #[test] + fn always_default() { + struct NoDefault; + RangeSet::::default(); + } + // impl Serialize #[cfg(feature = "serde1")]