Skip to content

Use generic impls for Hash #12820

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/libcollections/lru_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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) }
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/libextra/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Rust extras are part of the standard Rust distribution.
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)];
Expand Down
14 changes: 7 additions & 7 deletions src/libextra/url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -849,15 +849,15 @@ impl fmt::Show for Path {
}
}

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)
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/libstd/path/posix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use c_str::{CString, ToCStr};
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;
Expand Down Expand Up @@ -88,10 +88,10 @@ impl ToCStr for Path {
}
}

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)
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/libstd/path/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use clone::Clone;
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;
Expand Down Expand Up @@ -112,10 +112,10 @@ impl ToCStr for Path {
}
}

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)
}
}

Expand Down
11 changes: 7 additions & 4 deletions src/libstd/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ use clone::Clone;
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};
Expand Down Expand Up @@ -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),
}
}
}

Expand Down
15 changes: 11 additions & 4 deletions src/libuuid/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ Examples of string representations:
#[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;
Expand All @@ -71,7 +77,7 @@ use std::char::Char;
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;
Expand Down Expand Up @@ -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)
}
}

Expand Down