diff --git a/string/CHANGES.md b/string/CHANGES.md index 51bc67c2..53ab9c7a 100644 --- a/string/CHANGES.md +++ b/string/CHANGES.md @@ -1,5 +1,9 @@ # Changes +## [0.1.4] - 2020-01-14 + +* Fix `AsRef` impl + ## [0.1.3] - 2020-01-13 * Add `PartialEq>`, `AsRef<[u8]>` impls diff --git a/string/Cargo.toml b/string/Cargo.toml index 861c5e43..0031ea5b 100644 --- a/string/Cargo.toml +++ b/string/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bytestring" -version = "0.1.3" +version = "0.1.4" 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 b3c27b7e..6e5d422f 100644 --- a/string/src/lib.rs +++ b/string/src/lib.rs @@ -7,7 +7,7 @@ use bytes::Bytes; /// A utf-8 encoded string with [`Bytes`] as a storage. /// /// [`Bytes`]: https://docs.rs/bytes/0.5.3/bytes/struct.Bytes.html -#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Default)] +#[derive(Clone, Eq, Ord, PartialOrd, Default)] pub struct ByteString(Bytes); impl ByteString { @@ -55,6 +55,12 @@ impl AsRef<[u8]> for ByteString { } } +impl AsRef for ByteString { + fn as_ref(&self) -> &str { + &*self + } +} + impl hash::Hash for ByteString { fn hash(&self, state: &mut H) { (**self).hash(state); @@ -187,6 +193,8 @@ mod test { fn test_from_string() { let s: ByteString = "hello".to_string().into(); assert_eq!(&s, "hello"); + let t: &str = s.as_ref(); + assert_eq!(t, "hello"); } #[test]