From 2bcbd9c551d256e06e3e3044a2a99f79a7946449 Mon Sep 17 00:00:00 2001 From: Chris Morgan Date: Tue, 25 Jan 2022 21:53:49 +1100 Subject: [PATCH] HashMap feature parity: impl Extend, notes on more --- src/lib.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 6366c70..d4f227a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -71,6 +71,10 @@ macro_rules! impl_common_methods { 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 { @@ -203,6 +207,8 @@ impl Map { } } + // 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] @@ -233,6 +239,15 @@ impl Map { } } +impl Extend> for Map { + #[inline] + fn extend>>(&mut self, iter: T) { + for item in iter { + let _ = unsafe { self.raw.insert(item.type_id(), item) }; + } + } +} + impl AsRef> for Map { #[inline] fn as_ref(&self) -> &RawMap { -- 2.42.0