Skip to content

Commit 3e6b767

Browse files
committed
Clean up module
1 parent 4f944c6 commit 3e6b767

File tree

1 file changed

+38
-50
lines changed

1 file changed

+38
-50
lines changed

src/lib.rs

Lines changed: 38 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
1211
//! A HashMap wrapper that holds key-value pairs in insertion order.
1312
//!
1413
//! # Examples
@@ -30,7 +29,6 @@
3029
3130
#![forbid(missing_docs)]
3231
#![feature(hashmap_hasher)]
33-
#![feature(box_raw)]
3432
#![feature(iter_order)]
3533
#![cfg_attr(test, feature(test))]
3634

@@ -69,7 +67,7 @@ impl<K: Hash> Hash for KeyRef<K> {
6967
}
7068

7169
impl<K: PartialEq> PartialEq for KeyRef<K> {
72-
fn eq(&self, other: &KeyRef<K>) -> bool {
70+
fn eq(&self, other: &Self) -> bool {
7371
unsafe{ (*self.k).eq(&*other.k) }
7472
}
7573
}
@@ -83,7 +81,7 @@ impl<K: Eq> Eq for KeyRef<K> {}
8381
struct Qey<Q: ?Sized>(Q);
8482

8583
impl<Q: ?Sized> Qey<Q> {
86-
fn from_ref(q: &Q) -> &Qey<Q> { unsafe { mem::transmute(q) } }
84+
fn from_ref(q: &Q) -> &Self { unsafe { mem::transmute(q) } }
8785
}
8886

8987
impl<K, Q: ?Sized> Borrow<Qey<Q>> for KeyRef<K> where K: Borrow<Q> {
@@ -93,7 +91,7 @@ impl<K, Q: ?Sized> Borrow<Qey<Q>> for KeyRef<K> where K: Borrow<Q> {
9391
}
9492

9593
impl<K, V> LinkedHashMapEntry<K, V> {
96-
fn new(k: K, v: V) -> LinkedHashMapEntry<K, V> {
94+
fn new(k: K, v: V) -> Self {
9795
LinkedHashMapEntry {
9896
key: k,
9997
value: v,
@@ -112,11 +110,11 @@ unsafe fn drop_empty_entry_box<K, V>(the_box: *mut LinkedHashMapEntry<K, V>) {
112110

113111
impl<K: Hash + Eq, V> LinkedHashMap<K, V> {
114112
/// Creates a linked hash map.
115-
pub fn new() -> LinkedHashMap<K, V> { LinkedHashMap::with_map(HashMap::new()) }
113+
pub fn new() -> Self { Self::with_map(HashMap::new()) }
116114

117115
/// Creates an empty linked hash map with the given initial capacity.
118-
pub fn with_capacity(capacity: usize) -> LinkedHashMap<K, V> {
119-
LinkedHashMap::with_map(HashMap::with_capacity(capacity))
116+
pub fn with_capacity(capacity: usize) -> Self {
117+
Self::with_map(HashMap::with_capacity(capacity))
120118
}
121119
}
122120

@@ -135,7 +133,7 @@ impl<K, V, S> LinkedHashMap<K, V, S> {
135133
}
136134

137135
impl<K: Hash + Eq, V, S: HashState> LinkedHashMap<K, V, S> {
138-
fn with_map(map: HashMap<KeyRef<K>, Box<LinkedHashMapEntry<K, V>>, S>) -> LinkedHashMap<K, V, S> {
136+
fn with_map(map: HashMap<KeyRef<K>, Box<LinkedHashMapEntry<K, V>>, S>) -> Self {
139137
LinkedHashMap {
140138
map: map,
141139
head: ptr::null_mut(),
@@ -144,13 +142,13 @@ impl<K: Hash + Eq, V, S: HashState> LinkedHashMap<K, V, S> {
144142
}
145143

146144
/// Creates an empty linked hash map with the given initial hash state.
147-
pub fn with_hash_state(hash_state: S) -> LinkedHashMap<K, V, S> {
148-
LinkedHashMap::with_map(HashMap::with_hash_state(hash_state))
145+
pub fn with_hash_state(hash_state: S) -> Self {
146+
Self::with_map(HashMap::with_hash_state(hash_state))
149147
}
150148

151149
/// Creates an empty linked hash map with the given initial capacity and hash state.
152-
pub fn with_capacity_and_hash_state(capacity: usize, hash_state: S) -> LinkedHashMap<K, V, S> {
153-
LinkedHashMap::with_map(HashMap::with_capacity_and_hash_state(capacity, hash_state))
150+
pub fn with_capacity_and_hash_state(capacity: usize, hash_state: S) -> Self {
151+
Self::with_map(HashMap::with_capacity_and_hash_state(capacity, hash_state))
154152
}
155153

156154
/// Reserves capacity for at least `additional` more elements to be inserted into the map. The
@@ -378,7 +376,7 @@ impl<K: Hash + Eq, V, S: HashState> LinkedHashMap<K, V, S> {
378376
None
379377
}
380378

381-
/// Get the first entry.
379+
/// Gets the first entry.
382380
///
383381
/// # Examples
384382
///
@@ -424,7 +422,7 @@ impl<K: Hash + Eq, V, S: HashState> LinkedHashMap<K, V, S> {
424422
None
425423
}
426424

427-
/// Get the last entry.
425+
/// Gets the last entry.
428426
///
429427
/// # Examples
430428
///
@@ -451,7 +449,7 @@ impl<K: Hash + Eq, V, S: HashState> LinkedHashMap<K, V, S> {
451449
/// Returns whether the map is currently empty.
452450
pub fn is_empty(&self) -> bool { self.len() == 0 }
453451

454-
/// Clear the map of all key-value pairs.
452+
/// Clears the map of all key-value pairs.
455453
pub fn clear(&mut self) {
456454
self.map.clear();
457455
// update the guard node if present
@@ -620,13 +618,13 @@ impl<K: Hash + Eq, V, S: HashState> LinkedHashMap<K, V, S> {
620618
// `LinkedHashMap`s without cloning the original map and clearing it. For now, only
621619
// `LinkedHashMap<K, V>`s implement `Clone`.
622620
impl<K: Hash + Eq + Clone, V: Clone> Clone for LinkedHashMap<K, V> {
623-
fn clone(&self) -> LinkedHashMap<K, V> {
621+
fn clone(&self) -> Self {
624622
self.iter().map(|(k, v)| (k.clone(), v.clone())).collect()
625623
}
626624
}
627625

628626
impl<K: Hash + Eq, V, S: HashState + Default> Default for LinkedHashMap<K, V, S> {
629-
fn default() -> LinkedHashMap<K, V, S> { LinkedHashMap::with_hash_state(Default::default()) }
627+
fn default() -> Self { LinkedHashMap::with_hash_state(Default::default()) }
630628
}
631629

632630
impl<K: Hash + Eq, V, S: HashState> Extend<(K, V)> for LinkedHashMap<K, V, S> {
@@ -638,9 +636,9 @@ impl<K: Hash + Eq, V, S: HashState> Extend<(K, V)> for LinkedHashMap<K, V, S> {
638636
}
639637

640638
impl<K: Hash + Eq, V, S: HashState + Default> iter::FromIterator<(K, V)> for LinkedHashMap<K, V, S> {
641-
fn from_iter<I: IntoIterator<Item=(K, V)>>(iter: I) -> LinkedHashMap<K, V, S> {
639+
fn from_iter<I: IntoIterator<Item=(K, V)>>(iter: I) -> Self {
642640
let iter = iter.into_iter();
643-
let mut map = LinkedHashMap::with_capacity_and_hash_state(iter.size_hint().0, Default::default());
641+
let mut map = Self::with_capacity_and_hash_state(iter.size_hint().0, Default::default());
644642
map.extend(iter);
645643
map
646644
}
@@ -649,54 +647,47 @@ impl<K: Hash + Eq, V, S: HashState + Default> iter::FromIterator<(K, V)> for Lin
649647
impl<A: fmt::Debug + Hash + Eq, B: fmt::Debug, S: HashState> fmt::Debug for LinkedHashMap<A, B, S> {
650648
/// Returns a string that lists the key-value pairs in insertion order.
651649
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
652-
try!(write!(f, "{{"));
653-
654-
for (i, (k, v)) in self.iter().enumerate() {
655-
if i != 0 { try!(write!(f, ", ")); }
656-
try!(write!(f, "{:?}: {:?}", *k, *v));
657-
}
658-
659-
write!(f, "}}")
650+
f.debug_map().entries(self).finish()
660651
}
661652
}
662653

663654
impl<K: Hash + Eq, V: PartialEq, S: HashState> PartialEq for LinkedHashMap<K, V, S> {
664-
fn eq(&self, other: &LinkedHashMap<K, V, S>) -> bool {
665-
self.len() == other.len() && iter::order::eq(self.iter(), other.iter())
655+
fn eq(&self, other: &Self) -> bool {
656+
self.len() == other.len() && self.iter().eq(other)
666657
}
667658

668-
fn ne(&self, other: &LinkedHashMap<K, V, S>) -> bool {
669-
self.len() != other.len() || iter::order::ne(self.iter(), other.iter())
659+
fn ne(&self, other: &Self) -> bool {
660+
self.len() != other.len() || self.iter().ne(other)
670661
}
671662
}
672663

673664
impl<K: Hash + Eq, V: Eq, S: HashState> Eq for LinkedHashMap<K, V, S> {}
674665

675666
impl<K: Hash + Eq + PartialOrd, V: PartialOrd, S: HashState> PartialOrd for LinkedHashMap<K, V, S> {
676-
fn partial_cmp(&self, other: &LinkedHashMap<K, V, S>) -> Option<Ordering> {
677-
iter::order::partial_cmp(self.iter(), other.iter())
667+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
668+
self.iter().partial_cmp(other)
678669
}
679670

680-
fn lt(&self, other: &LinkedHashMap<K, V, S>) -> bool {
681-
iter::order::lt(self.iter(), other.iter())
671+
fn lt(&self, other: &Self) -> bool {
672+
self.iter().lt(other)
682673
}
683674

684-
fn le(&self, other: &LinkedHashMap<K, V, S>) -> bool {
685-
iter::order::le(self.iter(), other.iter())
675+
fn le(&self, other: &Self) -> bool {
676+
self.iter().le(other)
686677
}
687678

688-
fn ge(&self, other: &LinkedHashMap<K, V, S>) -> bool {
689-
iter::order::ge(self.iter(), other.iter())
679+
fn ge(&self, other: &Self) -> bool {
680+
self.iter().ge(other)
690681
}
691682

692-
fn gt(&self, other: &LinkedHashMap<K, V, S>) -> bool {
693-
iter::order::gt(self.iter(), other.iter())
683+
fn gt(&self, other: &Self) -> bool {
684+
self.iter().gt(other)
694685
}
695686
}
696687

697688
impl<K: Hash + Eq + Ord, V: Ord, S: HashState> Ord for LinkedHashMap<K, V, S> {
698-
fn cmp(&self, other: &LinkedHashMap<K, V, S>) -> Ordering {
699-
iter::order::cmp(self.iter(), other.iter())
689+
fn cmp(&self, other: &Self) -> Ordering {
690+
self.iter().cmp(other)
700691
}
701692
}
702693

@@ -738,7 +729,7 @@ pub struct IterMut<'a, K: 'a, V: 'a> {
738729
}
739730

740731
impl<'a, K, V> Clone for Iter<'a, K, V> {
741-
fn clone(&self) -> Iter<'a, K, V> { Iter { ..*self } }
732+
fn clone(&self) -> Self { Iter { ..*self } }
742733
}
743734

744735
impl<'a, K, V> Iterator for Iter<'a, K, V> {
@@ -821,14 +812,13 @@ impl<'a, K, V> ExactSizeIterator for IterMut<'a, K, V> {
821812
fn len(&self) -> usize { self.remaining }
822813
}
823814

824-
825815
/// An insertion-order iterator over a `LinkedHashMap`'s keys.
826816
pub struct Keys<'a, K: 'a, V: 'a> {
827817
inner: iter::Map<Iter<'a, K, V>, fn((&'a K, &'a V)) -> &'a K>
828818
}
829819

830820
impl<'a, K, V> Clone for Keys<'a, K, V> {
831-
fn clone(&self) -> Keys<'a, K, V> { Keys { inner: self.inner.clone() } }
821+
fn clone(&self) -> Self { Keys { inner: self.inner.clone() } }
832822
}
833823

834824
impl<'a, K, V> Iterator for Keys<'a, K, V> {
@@ -846,14 +836,13 @@ impl<'a, K, V> ExactSizeIterator for Keys<'a, K, V> {
846836
fn len(&self) -> usize { self.inner.len() }
847837
}
848838

849-
850839
/// An insertion-order iterator over a `LinkedHashMap`'s values.
851840
pub struct Values<'a, K: 'a, V: 'a> {
852841
inner: iter::Map<Iter<'a, K, V>, fn((&'a K, &'a V)) -> &'a V>
853842
}
854843

855844
impl<'a, K, V> Clone for Values<'a, K, V> {
856-
fn clone(&self) -> Values<'a, K, V> { Values { inner: self.inner.clone() } }
845+
fn clone(&self) -> Self { Values { inner: self.inner.clone() } }
857846
}
858847

859848
impl<'a, K, V> Iterator for Values<'a, K, V> {
@@ -1140,5 +1129,4 @@ mod tests {
11401129
}
11411130
})
11421131
}
1143-
11441132
}

0 commit comments

Comments
 (0)