1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-27 18:02:58 +01:00

Fix AsRef<str> impl

This commit is contained in:
Nikolay Kim 2020-01-14 15:06:02 -08:00
parent 2f89483635
commit fa800aeba3
3 changed files with 14 additions and 2 deletions

View File

@ -1,5 +1,9 @@
# Changes
## [0.1.4] - 2020-01-14
* Fix `AsRef<str>` impl
## [0.1.3] - 2020-01-13
* Add `PartialEq<T: AsRef<str>>`, `AsRef<[u8]>` impls

View File

@ -1,6 +1,6 @@
[package]
name = "bytestring"
version = "0.1.3"
version = "0.1.4"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
description = "A UTF-8 encoded string with Bytes as a storage"
keywords = ["actix"]

View File

@ -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<str> for ByteString {
fn as_ref(&self) -> &str {
&*self
}
}
impl hash::Hash for ByteString {
fn hash<H: hash::Hasher>(&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]