Chris Morgan
›
Git
›
anymap
› commitdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
patch
|
inline
| side by side (parent:
0a1c85f
)
commit
grep
author
committer
pickaxe
?
search:
re
HashMap feature parity: impl Extend, notes on more
author
Chris Morgan
<me@chrismorgan.info>
Tue, 25 Jan 2022 10:53:49 +0000
committer
Chris Morgan
<me@chrismorgan.info>
Tue, 25 Jan 2022 13:16:15 +0000
src/lib.rs
patch
|
blob
|
history
diff --git
a/src/lib.rs
b/src/lib.rs
index 6366c70b5a3781fda251734893cf2585d7f196bc..d4f227a293da168d6b4ffa0119ffc1c8aa7946f5 100644
(file)
--- a/
src/lib.rs
+++ b/
src/lib.rs
@@
-71,6
+71,10
@@
macro_rules! impl_common_methods {
self.$field.shrink_to_fit()
}
self.$field.shrink_to_fit()
}
+ // Additional stable methods (as of 1.60.0-nightly) that could be added:
+ // try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError> (1.57.0)
+ // shrink_to(&mut self, min_capacity: usize) (1.56.0)
+
/// Returns the number of items in the collection.
#[inline]
pub fn len(&self) -> usize {
/// Returns the number of items in the collection.
#[inline]
pub fn len(&self) -> usize {
@@
-203,6
+207,8
@@
impl<A: ?Sized + UncheckedAnyExt> Map<A> {
}
}
}
}
+ // rustc 1.60.0-nightly has another method try_insert that would be nice to add when stable.
+
/// Removes the `T` value from the collection,
/// returning it if there was one or `None` if there was not.
#[inline]
/// Removes the `T` value from the collection,
/// returning it if there was one or `None` if there was not.
#[inline]
@@
-233,6
+239,15
@@
impl<A: ?Sized + UncheckedAnyExt> Map<A> {
}
}
}
}
+impl<A: ?Sized + UncheckedAnyExt> Extend<Box<A>> for Map<A> {
+ #[inline]
+ fn extend<T: IntoIterator<Item = Box<A>>>(&mut self, iter: T) {
+ for item in iter {
+ let _ = unsafe { self.raw.insert(item.type_id(), item) };
+ }
+ }
+}
+
impl<A: ?Sized + UncheckedAnyExt> AsRef<RawMap<A>> for Map<A> {
#[inline]
fn as_ref(&self) -> &RawMap<A> {
impl<A: ?Sized + UncheckedAnyExt> AsRef<RawMap<A>> for Map<A> {
#[inline]
fn as_ref(&self) -> &RawMap<A> {