diff --git a/string/CHANGES.md b/string/CHANGES.md index 7d0a4b84..51bc67c2 100644 --- a/string/CHANGES.md +++ b/string/CHANGES.md @@ -1,5 +1,9 @@ # Changes +## [0.1.3] - 2020-01-13 + +* Add `PartialEq>`, `AsRef<[u8]>` impls + ## [0.1.2] - 2019-12-22 * Fix `new()` method diff --git a/string/Cargo.toml b/string/Cargo.toml index f38c6992..861c5e43 100644 --- a/string/Cargo.toml +++ b/string/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bytestring" -version = "0.1.2" +version = "0.1.3" 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 d6d48ffb..b3c27b7e 100644 --- a/string/src/lib.rs +++ b/string/src/lib.rs @@ -43,6 +43,18 @@ impl PartialEq for ByteString { } } +impl> PartialEq for ByteString { + fn eq(&self, other: &T) -> bool { + &self[..] == other.as_ref() + } +} + +impl AsRef<[u8]> for ByteString { + fn as_ref(&self) -> &[u8] { + self.0.as_ref() + } +} + impl hash::Hash for ByteString { fn hash(&self, state: &mut H) { (**self).hash(state); @@ -147,6 +159,14 @@ mod test { use std::collections::hash_map::DefaultHasher; use std::hash::{Hash, Hasher}; + #[test] + fn test_partial_eq() { + let s: ByteString = ByteString::from_static("test"); + assert_eq!(s, "test"); + assert_eq!(s, *"test"); + assert_eq!(s, "test".to_string()); + } + #[test] fn test_new() { let _: ByteString = ByteString::new();