mirror of
https://github.com/openharmony/third_party_rust_bytes.git
synced 2026-07-19 17:05:29 -04:00
Add convenience PartialEq for BytesMut and Bytes (#141)
Saves the cognitive load of having to wrap them in slices to compare them when that seems like what one would expect. Signed-off-by: Clint Byrum <clint@fewbar.com>
This commit is contained in:
@@ -2525,3 +2525,17 @@ impl<'a, T: ?Sized> PartialOrd<&'a T> for Bytes
|
||||
self.partial_cmp(&**other)
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq<BytesMut> for Bytes
|
||||
{
|
||||
fn eq(&self, other: &BytesMut) -> bool {
|
||||
&other[..] == &self[..]
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq<Bytes> for BytesMut
|
||||
{
|
||||
fn eq(&self, other: &Bytes) -> bool {
|
||||
&other[..] == &self[..]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -503,3 +503,14 @@ fn stress() {
|
||||
assert_eq!(*buf, data[..]);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn partial_eq_bytesmut() {
|
||||
let bytes = Bytes::from(&b"The quick red fox"[..]);
|
||||
let bytesmut = BytesMut::from(&b"The quick red fox"[..]);
|
||||
assert!(bytes == bytesmut);
|
||||
assert!(bytesmut == bytes);
|
||||
let bytes2 = Bytes::from(&b"Jumped over the lazy brown dog"[..]);
|
||||
assert!(bytes2 != bytesmut);
|
||||
assert!(bytesmut != bytes2);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user