]> git.lizzy.rs Git - rust.git/commitdiff
Use generic impls for `Hash`
authorErick Tryzelaar <erick.tryzelaar@gmail.com>
Tue, 25 Feb 2014 16:03:41 +0000 (08:03 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Wed, 12 Mar 2014 20:39:47 +0000 (13:39 -0700)
src/libcollections/lru_cache.rs
src/libextra/lib.rs
src/libextra/url.rs
src/libstd/path/posix.rs
src/libstd/path/windows.rs
src/libstd/str.rs
src/libuuid/lib.rs

index 0aace71813eba5942773f5beffe5fae9eb56acfd..28ea36fa2317a2a2597d47e05ff626bfae3beb6a 100644 (file)
@@ -39,7 +39,7 @@
 
 use std::cast;
 use std::container::Container;
-use std::hash::{Hash, sip};
+use std::hash::Hash;
 use std::fmt;
 use std::ptr;
 
@@ -62,9 +62,9 @@ pub struct LruCache<K, V> {
     priv tail: *mut LruEntry<K, V>,
 }
 
-impl<K: Hash> Hash for KeyRef<K> {
-    fn hash(&self, s: &mut sip::SipState) {
-        unsafe {(*self.k).hash(s)}
+impl<S, K: Hash<S>> Hash<S> for KeyRef<K> {
+    fn hash(&self, state: &mut S) {
+        unsafe { (*self.k).hash(state) }
     }
 }
 
index 673eb7e76de492e50fe4ba5ac24a7711f1e3889d..32de7bf08667fb941372fef7437ab62c3a6e4bcf 100644 (file)
@@ -29,7 +29,7 @@
       html_favicon_url = "http://www.rust-lang.org/favicon.ico",
       html_root_url = "http://static.rust-lang.org/doc/master")];
 
-#[feature(macro_rules, globs, managed_boxes, asm)];
+#[feature(macro_rules, globs, managed_boxes, asm, default_type_params)];
 
 #[deny(non_camel_case_types)];
 #[deny(missing_doc)];
index 5812aaa5038d09b5fe6a02c61697b0932641a473..6be90c0056d11774149f88929f404a6e45b9d106 100644 (file)
@@ -14,7 +14,7 @@
 
 use std::cmp::Eq;
 use std::fmt;
-use std::hash::{Hash, sip};
+use std::hash::Hash;
 use std::io::BufReader;
 use std::from_str::FromStr;
 use std::uint;
@@ -849,15 +849,15 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
     }
 }
 
-impl Hash for Url {
-    fn hash(&self, s: &mut sip::SipState) {
-        self.to_str().hash(s)
+impl<S: Writer> Hash<S> for Url {
+    fn hash(&self, state: &mut S) {
+        self.to_str().hash(state)
     }
 }
 
-impl Hash for Path {
-    fn hash(&self, s: &mut sip::SipState) {
-        self.to_str().hash(s)
+impl<S: Writer> Hash<S> for Path {
+    fn hash(&self, state: &mut S) {
+        self.to_str().hash(state)
     }
 }
 
index a3380b5db1d2bf7542238810a28b1c7fa6da97f1..f7588f6ca599c70e066cf6321c6e4a2ea33b8813 100644 (file)
@@ -15,7 +15,7 @@
 use clone::Clone;
 use cmp::Eq;
 use from_str::FromStr;
-use hash::{Hash, sip};
+use io::Writer;
 use iter::{AdditiveIterator, Extendable, Iterator, Map};
 use option::{Option, None, Some};
 use str;
@@ -88,10 +88,10 @@ unsafe fn to_c_str_unchecked(&self) -> CString {
     }
 }
 
-impl Hash for Path {
+impl<H: Writer> ::hash::Hash<H> for Path {
     #[inline]
-    fn hash(&self, s: &mut sip::SipState) {
-        self.repr.hash(s)
+    fn hash(&self, hasher: &mut H) {
+        self.repr.hash(hasher)
     }
 }
 
index 5b358819e4168f57f3486fabe0972355f64bbc90..6d05001beab927aba5702a17cf885021251ce59a 100644 (file)
@@ -17,7 +17,7 @@
 use container::Container;
 use cmp::Eq;
 use from_str::FromStr;
-use hash::{Hash, sip};
+use io::Writer;
 use iter::{AdditiveIterator, DoubleEndedIterator, Extendable, Rev, Iterator, Map};
 use option::{Option, Some, None};
 use str;
@@ -112,10 +112,10 @@ unsafe fn to_c_str_unchecked(&self) -> CString {
     }
 }
 
-impl Hash for Path {
+impl<H: Writer> ::hash::Hash<H> for Path {
     #[inline]
-    fn hash(&self, s: &mut sip::SipState) {
-        self.repr.hash(s)
+    fn hash(&self, hasher: &mut H) {
+        self.repr.hash(hasher)
     }
 }
 
index 5bd14e717b1b91b11eb246a31b07b47af2b41b24..1900d0ffedd4ff595e77c26d1dac8493620a7859 100644 (file)
@@ -89,7 +89,7 @@ fn main() {
 use cmp::{Eq, TotalEq, Ord, TotalOrd, Equiv, Ordering};
 use container::{Container, Mutable};
 use fmt;
-use hash::{Hash, sip};
+use io::Writer;
 use iter::{Iterator, FromIterator, Extendable, range};
 use iter::{Filter, AdditiveIterator, Map};
 use iter::{Rev, DoubleEndedIterator, ExactSize};
@@ -1331,10 +1331,13 @@ impl<'a> Default for MaybeOwned<'a> {
     fn default() -> MaybeOwned<'a> { Slice("") }
 }
 
-impl<'a> Hash for MaybeOwned<'a> {
+impl<'a, H: Writer> ::hash::Hash<H> for MaybeOwned<'a> {
     #[inline]
-    fn hash(&self, s: &mut sip::SipState) {
-        self.as_slice().hash(s)
+    fn hash(&self, hasher: &mut H) {
+        match *self {
+            Slice(s) => s.hash(hasher),
+            Owned(ref s) => s.hash(hasher),
+        }
     }
 }
 
index aa17cd468094809a9a658e82220abf5890e9083a..922393d8bb3af09a44a7d64773a696ff2d3101e3 100644 (file)
@@ -59,6 +59,12 @@ fn main() {
 #[crate_type = "dylib"];
 #[license = "MIT/ASL2"];
 
+#[feature(default_type_params)];
+
+// NOTE remove the following two attributes after the next snapshot.
+#[allow(unrecognized_lint)];
+#[allow(default_type_param_usage)];
+
 // test harness access
 #[cfg(test)]
 extern crate test;
@@ -71,7 +77,7 @@ fn main() {
 use std::default::Default;
 use std::fmt;
 use std::from_str::FromStr;
-use std::hash::{Hash, sip};
+use std::hash::Hash;
 use std::num::FromStrRadix;
 use std::str;
 use std::vec;
@@ -116,9 +122,10 @@ pub struct Uuid {
     /// The 128-bit number stored in 16 bytes
     bytes: UuidBytes
 }
-impl Hash for Uuid {
-    fn hash(&self, s: &mut sip::SipState) {
-        self.bytes.slice_from(0).hash(s)
+
+impl<S: Writer> Hash<S> for Uuid {
+    fn hash(&self, state: &mut S) {
+        self.bytes.hash(state)
     }
 }