1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-06-28 20:10:35 +02:00

Add PartialEq<T: AsRef<str>>, AsRef<[u8]> impls

This commit is contained in:
Nikolay Kim
2020-01-13 11:58:31 +06:00
parent 7c5fa25b23
commit 3048073919
3 changed files with 25 additions and 1 deletions

View File

@ -43,6 +43,18 @@ impl PartialEq<str> for ByteString {
}
}
impl<T: AsRef<str>> PartialEq<T> 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<H: hash::Hasher>(&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();