Skip to content

Commit 9959188

Browse files
ericktalexcrichton
authored andcommitted
Use generic impls for Hash
1 parent 207ebf1 commit 9959188

File tree

7 files changed

+38
-28
lines changed

7 files changed

+38
-28
lines changed

src/libcollections/lru_cache.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
4040
use std::cast;
4141
use std::container::Container;
42-
use std::hash::{Hash, sip};
42+
use std::hash::Hash;
4343
use std::fmt;
4444
use std::ptr;
4545

@@ -62,9 +62,9 @@ pub struct LruCache<K, V> {
6262
priv tail: *mut LruEntry<K, V>,
6363
}
6464

65-
impl<K: Hash> Hash for KeyRef<K> {
66-
fn hash(&self, s: &mut sip::SipState) {
67-
unsafe {(*self.k).hash(s)}
65+
impl<S, K: Hash<S>> Hash<S> for KeyRef<K> {
66+
fn hash(&self, state: &mut S) {
67+
unsafe { (*self.k).hash(state) }
6868
}
6969
}
7070

src/libextra/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Rust extras are part of the standard Rust distribution.
2929
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
3030
html_root_url = "http://static.rust-lang.org/doc/master")];
3131

32-
#[feature(macro_rules, globs, managed_boxes, asm)];
32+
#[feature(macro_rules, globs, managed_boxes, asm, default_type_params)];
3333

3434
#[deny(non_camel_case_types)];
3535
#[deny(missing_doc)];

src/libextra/url.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
use std::cmp::Eq;
1616
use std::fmt;
17-
use std::hash::{Hash, sip};
17+
use std::hash::Hash;
1818
use std::io::BufReader;
1919
use std::from_str::FromStr;
2020
use std::uint;
@@ -849,15 +849,15 @@ impl fmt::Show for Path {
849849
}
850850
}
851851

852-
impl Hash for Url {
853-
fn hash(&self, s: &mut sip::SipState) {
854-
self.to_str().hash(s)
852+
impl<S: Writer> Hash<S> for Url {
853+
fn hash(&self, state: &mut S) {
854+
self.to_str().hash(state)
855855
}
856856
}
857857

858-
impl Hash for Path {
859-
fn hash(&self, s: &mut sip::SipState) {
860-
self.to_str().hash(s)
858+
impl<S: Writer> Hash<S> for Path {
859+
fn hash(&self, state: &mut S) {
860+
self.to_str().hash(state)
861861
}
862862
}
863863

src/libstd/path/posix.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use c_str::{CString, ToCStr};
1515
use clone::Clone;
1616
use cmp::Eq;
1717
use from_str::FromStr;
18-
use hash::{Hash, sip};
18+
use io::Writer;
1919
use iter::{AdditiveIterator, Extendable, Iterator, Map};
2020
use option::{Option, None, Some};
2121
use str;
@@ -88,10 +88,10 @@ impl ToCStr for Path {
8888
}
8989
}
9090

91-
impl Hash for Path {
91+
impl<H: Writer> ::hash::Hash<H> for Path {
9292
#[inline]
93-
fn hash(&self, s: &mut sip::SipState) {
94-
self.repr.hash(s)
93+
fn hash(&self, hasher: &mut H) {
94+
self.repr.hash(hasher)
9595
}
9696
}
9797

src/libstd/path/windows.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use clone::Clone;
1717
use container::Container;
1818
use cmp::Eq;
1919
use from_str::FromStr;
20-
use hash::{Hash, sip};
20+
use io::Writer;
2121
use iter::{AdditiveIterator, DoubleEndedIterator, Extendable, Rev, Iterator, Map};
2222
use option::{Option, Some, None};
2323
use str;
@@ -112,10 +112,10 @@ impl ToCStr for Path {
112112
}
113113
}
114114

115-
impl Hash for Path {
115+
impl<H: Writer> ::hash::Hash<H> for Path {
116116
#[inline]
117-
fn hash(&self, s: &mut sip::SipState) {
118-
self.repr.hash(s)
117+
fn hash(&self, hasher: &mut H) {
118+
self.repr.hash(hasher)
119119
}
120120
}
121121

src/libstd/str.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ use clone::Clone;
8989
use cmp::{Eq, TotalEq, Ord, TotalOrd, Equiv, Ordering};
9090
use container::{Container, Mutable};
9191
use fmt;
92-
use hash::{Hash, sip};
92+
use io::Writer;
9393
use iter::{Iterator, FromIterator, Extendable, range};
9494
use iter::{Filter, AdditiveIterator, Map};
9595
use iter::{Rev, DoubleEndedIterator, ExactSize};
@@ -1331,10 +1331,13 @@ impl<'a> Default for MaybeOwned<'a> {
13311331
fn default() -> MaybeOwned<'a> { Slice("") }
13321332
}
13331333

1334-
impl<'a> Hash for MaybeOwned<'a> {
1334+
impl<'a, H: Writer> ::hash::Hash<H> for MaybeOwned<'a> {
13351335
#[inline]
1336-
fn hash(&self, s: &mut sip::SipState) {
1337-
self.as_slice().hash(s)
1336+
fn hash(&self, hasher: &mut H) {
1337+
match *self {
1338+
Slice(s) => s.hash(hasher),
1339+
Owned(ref s) => s.hash(hasher),
1340+
}
13381341
}
13391342
}
13401343

src/libuuid/lib.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ Examples of string representations:
5959
#[crate_type = "dylib"];
6060
#[license = "MIT/ASL2"];
6161

62+
#[feature(default_type_params)];
63+
64+
// NOTE remove the following two attributes after the next snapshot.
65+
#[allow(unrecognized_lint)];
66+
#[allow(default_type_param_usage)];
67+
6268
// test harness access
6369
#[cfg(test)]
6470
extern crate test;
@@ -71,7 +77,7 @@ use std::char::Char;
7177
use std::default::Default;
7278
use std::fmt;
7379
use std::from_str::FromStr;
74-
use std::hash::{Hash, sip};
80+
use std::hash::Hash;
7581
use std::num::FromStrRadix;
7682
use std::str;
7783
use std::vec;
@@ -116,9 +122,10 @@ pub struct Uuid {
116122
/// The 128-bit number stored in 16 bytes
117123
bytes: UuidBytes
118124
}
119-
impl Hash for Uuid {
120-
fn hash(&self, s: &mut sip::SipState) {
121-
self.bytes.slice_from(0).hash(s)
125+
126+
impl<S: Writer> Hash<S> for Uuid {
127+
fn hash(&self, state: &mut S) {
128+
self.bytes.hash(state)
122129
}
123130
}
124131

0 commit comments

Comments
 (0)