Implement Default on Map

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 <mjkoo90@gmail.com> for the fix.
This commit is contained in:
Chris Morgan 2017-10-02 14:32:51 +11:00
parent f5e887ef63
commit 0850f5ec36
3 changed files with 15 additions and 7 deletions

View file

@ -5,6 +5,8 @@
dont signify). Technically a [breaking-change], but it was something for
development only, so Im not in the slightest bit concerned by it.
- Implement `Default` on `Map` (not just on `RawMap`)
I dont plan for there to be any real changes from 0.12.1;
it should be just a bit of housecleaning and a version bump.

View file

@ -75,6 +75,13 @@ macro_rules! impl_common_methods {
self.$field.clear()
}
}
impl<A: ?Sized + UncheckedAnyExt> Default for $t<A> {
#[inline]
fn default() -> $t<A> {
$t::new()
}
}
}
}
@ -389,6 +396,12 @@ mod tests {
test_entry!(test_entry_any, AnyMap);
test_entry!(test_entry_cloneany, Map<CloneAny>);
#[test]
fn test_default() {
let map: AnyMap = Default::default();
assert_eq!(map.len(), 0);
}
#[test]
fn test_clone() {
let mut map: Map<CloneAny> = Map::new();

View file

@ -70,13 +70,6 @@ impl<A: ?Sized + UncheckedAnyExt> Clone for RawMap<A> where Box<A>: Clone {
}
}
impl<A: ?Sized + UncheckedAnyExt> Default for RawMap<A> {
#[inline]
fn default() -> RawMap<A> {
RawMap::new()
}
}
impl_common_methods! {
field: RawMap.inner;
new() => HashMap::with_hasher(Default::default());