From 0850f5ec36b14904ae452ffdfa0a2ae0ba05c854 Mon Sep 17 00:00:00 2001 From: Chris Morgan Date: Mon, 2 Oct 2017 14:32:51 +1100 Subject: [PATCH] Implement Default on Map MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit It was implemented on RawMap, and I’m not sure quite why it wasn’t implemented on Map. I can’t think of any reason *not* to, though, so we might as well. Closes #30. Thanks to Maxwell Koo for the fix. --- CHANGELOG.md | 2 ++ src/lib.rs | 13 +++++++++++++ src/raw.rs | 7 ------- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a968dc..9691d8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ don’t signify). Technically a [breaking-change], but it was something for development only, so I’m not in the slightest bit concerned by it. +- Implement `Default` on `Map` (not just on `RawMap`) + I don’t plan for there to be any real changes from 0.12.1; it should be just a bit of housecleaning and a version bump. diff --git a/src/lib.rs b/src/lib.rs index bcd5c23..de03fb6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -75,6 +75,13 @@ macro_rules! impl_common_methods { self.$field.clear() } } + + impl Default for $t { + #[inline] + fn default() -> $t { + $t::new() + } + } } } @@ -389,6 +396,12 @@ mod tests { test_entry!(test_entry_any, AnyMap); test_entry!(test_entry_cloneany, Map); + #[test] + fn test_default() { + let map: AnyMap = Default::default(); + assert_eq!(map.len(), 0); + } + #[test] fn test_clone() { let mut map: Map = Map::new(); diff --git a/src/raw.rs b/src/raw.rs index 17c3869..07dccf8 100644 --- a/src/raw.rs +++ b/src/raw.rs @@ -70,13 +70,6 @@ impl Clone for RawMap where Box: Clone { } } -impl Default for RawMap { - #[inline] - fn default() -> RawMap { - RawMap::new() - } -} - impl_common_methods! { field: RawMap.inner; new() => HashMap::with_hasher(Default::default()); -- 2.42.0