diff options
| author | bors <bors@rust-lang.org> | 2015-02-19 18:36:59 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-02-19 18:36:59 +0000 |
| commit | 522d09dfecbeca1595f25ac58c6d0178bbd21d7d (patch) | |
| tree | cc0252dd3413e5f890d0ebcfdaa096e5b002be0b /src/libcoretest/hash/mod.rs | |
| parent | 0b664bb8436f2cfda7f13a6f302ab486f332816f (diff) | |
| parent | 49771bafa5fca16486bfd06741dac3de2c587adf (diff) | |
| download | rust-1.0.0-alpha.2.tar.gz rust-1.0.0-alpha.2.zip | |
Auto merge of #22541 - Manishearth:rollup, r=Gankro 1.0.0-alpha.2
Continued from #22520
Diffstat (limited to 'src/libcoretest/hash/mod.rs')
| -rw-r--r-- | src/libcoretest/hash/mod.rs | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/src/libcoretest/hash/mod.rs b/src/libcoretest/hash/mod.rs index fd0d3c676a4..9b6af182f72 100644 --- a/src/libcoretest/hash/mod.rs +++ b/src/libcoretest/hash/mod.rs @@ -9,7 +9,7 @@ // except according to those terms. use std::mem; -use std::hash::{Hash, Hasher, Writer}; +use std::hash::{Hash, Hasher}; use std::default::Default; struct MyHasher { @@ -22,25 +22,19 @@ impl Default for MyHasher { } } -impl Writer for MyHasher { - // Most things we'll just add up the bytes. +impl Hasher for MyHasher { fn write(&mut self, buf: &[u8]) { for byte in buf { self.hash += *byte as u64; } } -} - -impl Hasher for MyHasher { - type Output = u64; - fn reset(&mut self) { self.hash = 0; } fn finish(&self) -> u64 { self.hash } } #[test] fn test_writer_hasher() { - fn hash<T: Hash<MyHasher>>(t: &T) -> u64 { + fn hash<T: Hash>(t: &T) -> u64 { ::std::hash::hash::<_, MyHasher>(t) } @@ -90,9 +84,9 @@ struct Custom { hash: u64 } struct CustomHasher { output: u64 } impl Hasher for CustomHasher { - type Output = u64; - fn reset(&mut self) { self.output = 0; } fn finish(&self) -> u64 { self.output } + fn write(&mut self, data: &[u8]) { panic!() } + fn write_u64(&mut self, data: u64) { self.output = data; } } impl Default for CustomHasher { @@ -101,15 +95,15 @@ impl Default for CustomHasher { } } -impl Hash<CustomHasher> for Custom { - fn hash(&self, state: &mut CustomHasher) { - state.output = self.hash; +impl Hash for Custom { + fn hash<H: Hasher>(&self, state: &mut H) { + state.write_u64(self.hash); } } #[test] fn test_custom_state() { - fn hash<T: Hash<CustomHasher>>(t: &T) -> u64 { + fn hash<T: Hash>(t: &T) -> u64 { ::std::hash::hash::<_, CustomHasher>(t) } |
