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:
parent
f5e887ef63
commit
0850f5ec36
|
@ -5,6 +5,8 @@
|
||||||
don’t signify). Technically a [breaking-change], but it was something for
|
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.
|
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;
|
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.
|
it should be just a bit of housecleaning and a version bump.
|
||||||
|
|
||||||
|
|
13
src/lib.rs
13
src/lib.rs
|
@ -75,6 +75,13 @@ macro_rules! impl_common_methods {
|
||||||
self.$field.clear()
|
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_any, AnyMap);
|
||||||
test_entry!(test_entry_cloneany, Map<CloneAny>);
|
test_entry!(test_entry_cloneany, Map<CloneAny>);
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_default() {
|
||||||
|
let map: AnyMap = Default::default();
|
||||||
|
assert_eq!(map.len(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_clone() {
|
fn test_clone() {
|
||||||
let mut map: Map<CloneAny> = Map::new();
|
let mut map: Map<CloneAny> = Map::new();
|
||||||
|
|
|
@ -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! {
|
impl_common_methods! {
|
||||||
field: RawMap.inner;
|
field: RawMap.inner;
|
||||||
new() => HashMap::with_hasher(Default::default());
|
new() => HashMap::with_hasher(Default::default());
|
||||||
|
|
Loading…
Reference in a new issue