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:
parent
2f89483635
commit
fa800aeba3
@ -1,5 +1,9 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [0.1.4] - 2020-01-14
|
||||||
|
|
||||||
|
* Fix `AsRef<str>` impl
|
||||||
|
|
||||||
## [0.1.3] - 2020-01-13
|
## [0.1.3] - 2020-01-13
|
||||||
|
|
||||||
* Add `PartialEq<T: AsRef<str>>`, `AsRef<[u8]>` impls
|
* Add `PartialEq<T: AsRef<str>>`, `AsRef<[u8]>` impls
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "bytestring"
|
name = "bytestring"
|
||||||
version = "0.1.3"
|
version = "0.1.4"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "A UTF-8 encoded string with Bytes as a storage"
|
description = "A UTF-8 encoded string with Bytes as a storage"
|
||||||
keywords = ["actix"]
|
keywords = ["actix"]
|
||||||
|
@ -7,7 +7,7 @@ use bytes::Bytes;
|
|||||||
/// A utf-8 encoded string with [`Bytes`] as a storage.
|
/// A utf-8 encoded string with [`Bytes`] as a storage.
|
||||||
///
|
///
|
||||||
/// [`Bytes`]: https://docs.rs/bytes/0.5.3/bytes/struct.Bytes.html
|
/// [`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);
|
pub struct ByteString(Bytes);
|
||||||
|
|
||||||
impl ByteString {
|
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 {
|
impl hash::Hash for ByteString {
|
||||||
fn hash<H: hash::Hasher>(&self, state: &mut H) {
|
fn hash<H: hash::Hasher>(&self, state: &mut H) {
|
||||||
(**self).hash(state);
|
(**self).hash(state);
|
||||||
@ -187,6 +193,8 @@ mod test {
|
|||||||
fn test_from_string() {
|
fn test_from_string() {
|
||||||
let s: ByteString = "hello".to_string().into();
|
let s: ByteString = "hello".to_string().into();
|
||||||
assert_eq!(&s, "hello");
|
assert_eq!(&s, "hello");
|
||||||
|
let t: &str = s.as_ref();
|
||||||
|
assert_eq!(t, "hello");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
Reference in New Issue
Block a user