Skip to content

Commit 3cefbd6

Browse files
committed
Merge pull request #44 from apasel422/update
Assorted updates
2 parents de24681 + c79f016 commit 3cefbd6

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

.travis.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
language: rust
2-
rust:
3-
- nightly
42
sudo: false
3+
matrix:
4+
include:
5+
- rust: beta
6+
- rust: nightly
7+
env: FEATURES="--features nightly"
58
script:
6-
- cargo build
7-
- cargo test
8-
- cargo doc --no-deps
9+
- cargo build $FEATURES
10+
- cargo test $FEATURES
11+
- cargo doc --no-deps $FEATURES
912
after_success: |
13+
[ $TRAVIS_RUST_VERSION = nightly ] &&
1014
[ $TRAVIS_BRANCH = master ] &&
1115
[ $TRAVIS_PULL_REQUEST = false ] &&
1216
bash deploy-docs.sh

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ homepage = "https://github.com/contain-rs/linked-hash-map"
1414
documentation = "https://contain-rs.github.io/linked-hash-map/linked_hash_map"
1515
keywords = ["data-structures"]
1616
readme = "README.md"
17+
18+
[features]
19+
nightly = []

src/lib.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
//! ```
2929
3030
#![forbid(missing_docs)]
31-
#![cfg_attr(test, feature(test))]
31+
#![cfg_attr(feature = "nightly", feature(hashmap_public_hasher))]
32+
#![cfg_attr(all(feature = "nightly", test), feature(test))]
3233

3334
use std::borrow::Borrow;
3435
use std::cmp::Ordering;
@@ -611,15 +612,22 @@ impl<K: Hash + Eq, V, S: BuildHasher> LinkedHashMap<K, V, S> {
611612
}
612613
}
613614

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"))]
617616
impl<K: Hash + Eq + Clone, V: Clone> Clone for LinkedHashMap<K, V> {
618617
fn clone(&self) -> Self {
619618
self.iter().map(|(k, v)| (k.clone(), v.clone())).collect()
620619
}
621620
}
622621

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+
623631
impl<K: Hash + Eq, V, S: BuildHasher + Default> Default for LinkedHashMap<K, V, S> {
624632
fn default() -> Self { LinkedHashMap::with_hash_state(Default::default()) }
625633
}
@@ -632,6 +640,16 @@ impl<K: Hash + Eq, V, S: BuildHasher> Extend<(K, V)> for LinkedHashMap<K, V, S>
632640
}
633641
}
634642

643+
impl<'a, K, V, S> Extend<(&'a K, &'a V)> for LinkedHashMap<K, V, S>
644+
where K: 'a + Hash + Eq + Copy, V: 'a + Copy, S: BuildHasher,
645+
{
646+
fn extend<I: IntoIterator<Item = (&'a K, &'a V)>>(&mut self, iter: I) {
647+
for (&k, &v) in iter {
648+
self.insert(k, v);
649+
}
650+
}
651+
}
652+
635653
impl<K: Hash + Eq, V, S: BuildHasher + Default> iter::FromIterator<(K, V)> for LinkedHashMap<K, V, S> {
636654
fn from_iter<I: IntoIterator<Item=(K, V)>>(iter: I) -> Self {
637655
let iter = iter.into_iter();
@@ -877,7 +895,7 @@ impl<'a, K: Hash + Eq, V, S: BuildHasher> IntoIterator for &'a mut LinkedHashMap
877895
fn into_iter(self) -> IterMut<'a, K, V> { self.iter_mut() }
878896
}
879897

880-
#[cfg(test)]
898+
#[cfg(all(feature = "nightly", test))]
881899
mod bench {
882900
extern crate test;
883901

0 commit comments

Comments
 (0)