mirror of
https://github.com/fafhrd91/actix-net
synced 2025-06-28 20:10:35 +02:00
Fix AsRef<str> impl
This commit is contained in:
@ -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]
|
||||
|
Reference in New Issue
Block a user