From c38a25f102a4ad0dd01fa8f9675b156634f3bd30 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Sat, 7 Dec 2019 11:51:47 +0600 Subject: [PATCH] fix hash impl --- string/CHANGES.md | 4 ++++ string/Cargo.toml | 2 +- string/src/lib.rs | 15 ++++++++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/string/CHANGES.md b/string/CHANGES.md index d01c5f7f..10c8d426 100644 --- a/string/CHANGES.md +++ b/string/CHANGES.md @@ -1,5 +1,9 @@ # Changes +[0.1.1] - 2019-12-07 + +* Fix hash impl + [0.1.0] - 2019-12-07 * Initial release diff --git a/string/Cargo.toml b/string/Cargo.toml index f3c2014c..69b9688c 100644 --- a/string/Cargo.toml +++ b/string/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bytestring" -version = "0.1.0" +version = "0.1.1" authors = ["Nikolay Kim "] description = "A UTF-8 encoded string with Bytes as a storage" keywords = ["actix"] diff --git a/string/src/lib.rs b/string/src/lib.rs index a458f294..ed3a4896 100644 --- a/string/src/lib.rs +++ b/string/src/lib.rs @@ -45,7 +45,7 @@ impl PartialEq for ByteString { impl hash::Hash for ByteString { fn hash(&self, state: &mut H) { - self.0.hash(state); + (**self).hash(state); } } @@ -144,6 +144,19 @@ impl fmt::Display for ByteString { #[cfg(test)] mod test { use super::*; + use std::collections::hash_map::DefaultHasher; + use std::hash::{Hash, Hasher}; + + #[test] + fn test_hash() { + let mut hasher1 = DefaultHasher::default(); + "str".hash(&mut hasher1); + + let mut hasher2 = DefaultHasher::default(); + let s = ByteString::from_static("str"); + s.hash(&mut hasher2); + assert_eq!(hasher1.finish(), hasher2.finish()); + } #[test] fn test_from_string() {