|
28 | 28 | //! ```
|
29 | 29 |
|
30 | 30 | #![forbid(missing_docs)]
|
| 31 | +#![cfg_attr(feature = "nightly", feature(hashmap_public_hasher))] |
31 | 32 | #![cfg_attr(all(feature = "nightly", test), feature(test))]
|
32 | 33 |
|
33 | 34 | use std::borrow::Borrow;
|
@@ -611,15 +612,22 @@ impl<K: Hash + Eq, V, S: BuildHasher> LinkedHashMap<K, V, S> {
|
611 | 612 | }
|
612 | 613 | }
|
613 | 614 |
|
614 |
| -// FIXME: `HashMap` doesn't expose its hash state, so we cannot clone fully parameterized |
615 |
| -// `LinkedHashMap`s without cloning the original map and clearing it. For now, only |
616 |
| -// `LinkedHashMap<K, V>`s implement `Clone`. |
| 615 | +#[cfg(not(feature = "nightly"))] |
617 | 616 | impl<K: Hash + Eq + Clone, V: Clone> Clone for LinkedHashMap<K, V> {
|
618 | 617 | fn clone(&self) -> Self {
|
619 | 618 | self.iter().map(|(k, v)| (k.clone(), v.clone())).collect()
|
620 | 619 | }
|
621 | 620 | }
|
622 | 621 |
|
| 622 | +#[cfg(feature = "nightly")] |
| 623 | +impl<K: Hash + Eq + Clone, V: Clone, S: BuildHasher + Clone> Clone for LinkedHashMap<K, V, S> { |
| 624 | + fn clone(&self) -> Self { |
| 625 | + let mut map = Self::with_hash_state(self.map.hasher().clone()); |
| 626 | + map.extend(self.iter().map(|(k, v)| (k.clone(), v.clone()))); |
| 627 | + map |
| 628 | + } |
| 629 | +} |
| 630 | + |
623 | 631 | impl<K: Hash + Eq, V, S: BuildHasher + Default> Default for LinkedHashMap<K, V, S> {
|
624 | 632 | fn default() -> Self { LinkedHashMap::with_hash_state(Default::default()) }
|
625 | 633 | }
|
|
0 commit comments