From 9959188d0e653871b4995a25ce066dbf0726f132 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Tue, 25 Feb 2014 08:03:41 -0800 Subject: [PATCH] Use generic impls for `Hash` --- src/libcollections/lru_cache.rs | 8 ++++---- src/libextra/lib.rs | 2 +- src/libextra/url.rs | 14 +++++++------- src/libstd/path/posix.rs | 8 ++++---- src/libstd/path/windows.rs | 8 ++++---- src/libstd/str.rs | 11 +++++++---- src/libuuid/lib.rs | 15 +++++++++++---- 7 files changed, 38 insertions(+), 28 deletions(-) diff --git a/src/libcollections/lru_cache.rs b/src/libcollections/lru_cache.rs index 0aace71813e..28ea36fa231 100644 --- a/src/libcollections/lru_cache.rs +++ b/src/libcollections/lru_cache.rs @@ -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 { priv tail: *mut LruEntry, } -impl Hash for KeyRef { - fn hash(&self, s: &mut sip::SipState) { - unsafe {(*self.k).hash(s)} +impl> Hash for KeyRef { + fn hash(&self, state: &mut S) { + unsafe { (*self.k).hash(state) } } } diff --git a/src/libextra/lib.rs b/src/libextra/lib.rs index 673eb7e76de..32de7bf0866 100644 --- a/src/libextra/lib.rs +++ b/src/libextra/lib.rs @@ -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)]; diff --git a/src/libextra/url.rs b/src/libextra/url.rs index 5812aaa5038..6be90c0056d 100644 --- a/src/libextra/url.rs +++ b/src/libextra/url.rs @@ -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 Hash 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 Hash for Path { + fn hash(&self, state: &mut S) { + self.to_str().hash(state) } } diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index a3380b5db1d..f7588f6ca59 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -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 ::hash::Hash for Path { #[inline] - fn hash(&self, s: &mut sip::SipState) { - self.repr.hash(s) + fn hash(&self, hasher: &mut H) { + self.repr.hash(hasher) } } diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 5b358819e41..6d05001beab 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -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 ::hash::Hash for Path { #[inline] - fn hash(&self, s: &mut sip::SipState) { - self.repr.hash(s) + fn hash(&self, hasher: &mut H) { + self.repr.hash(hasher) } } diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 5bd14e717b1..1900d0ffedd 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -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 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), + } } } diff --git a/src/libuuid/lib.rs b/src/libuuid/lib.rs index aa17cd46809..922393d8bb3 100644 --- a/src/libuuid/lib.rs +++ b/src/libuuid/lib.rs @@ -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 Hash for Uuid { + fn hash(&self, state: &mut S) { + self.bytes.hash(state) } }