mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-22 00:00:15 +02:00
Update for new blanket impl rules.
This commit is contained in:
+37
-28
@@ -254,41 +254,50 @@ pub trait ByteStr : Clone + Sized + Send + Sync + Reflect + ToBytes + ops::Index
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B1: ByteStr, B2: ByteStr> cmp::PartialEq<B2> for B1 {
|
macro_rules! impl_parteq {
|
||||||
fn eq(&self, other: &B2) -> bool {
|
($ty:ty) => {
|
||||||
if self.len() != other.len() {
|
impl<B: ByteStr> cmp::PartialEq<B> for $ty {
|
||||||
return false;
|
fn eq(&self, other: &B) -> bool {
|
||||||
}
|
if self.len() != other.len() {
|
||||||
|
|
||||||
let mut buf1 = self.buf();
|
|
||||||
let mut buf2 = self.buf();
|
|
||||||
|
|
||||||
while buf1.has_remaining() {
|
|
||||||
let len;
|
|
||||||
|
|
||||||
{
|
|
||||||
let b1 = buf1.bytes();
|
|
||||||
let b2 = buf2.bytes();
|
|
||||||
|
|
||||||
len = cmp::min(b1.len(), b2.len());
|
|
||||||
|
|
||||||
if b1[..len] != b2[..len] {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut buf1 = self.buf();
|
||||||
|
let mut buf2 = self.buf();
|
||||||
|
|
||||||
|
while buf1.has_remaining() {
|
||||||
|
let len;
|
||||||
|
|
||||||
|
{
|
||||||
|
let b1 = buf1.bytes();
|
||||||
|
let b2 = buf2.bytes();
|
||||||
|
|
||||||
|
len = cmp::min(b1.len(), b2.len());
|
||||||
|
|
||||||
|
if b1[..len] != b2[..len] {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
buf1.advance(len);
|
||||||
|
buf2.advance(len);
|
||||||
|
}
|
||||||
|
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
buf1.advance(len);
|
fn ne(&self, other: &B) -> bool {
|
||||||
buf2.advance(len);
|
return !self.eq(other)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
fn ne(&self, other: &B2) -> bool {
|
|
||||||
return !self.eq(other)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl_parteq!(SeqByteStr);
|
||||||
|
impl_parteq!(SmallByteStr);
|
||||||
|
impl_parteq!(Bytes);
|
||||||
|
impl_parteq!(Rope);
|
||||||
|
|
||||||
macro_rules! impl_eq {
|
macro_rules! impl_eq {
|
||||||
($ty:ty) => {
|
($ty:ty) => {
|
||||||
impl cmp::Eq for $ty {}
|
impl cmp::Eq for $ty {}
|
||||||
@@ -549,7 +558,7 @@ impl_write!(MutByteBuf);
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#[derive(Copy, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub enum BufError {
|
pub enum BufError {
|
||||||
Underflow,
|
Underflow,
|
||||||
Overflow,
|
Overflow,
|
||||||
|
|||||||
+1
-1
@@ -36,7 +36,7 @@ pub fn test_rope_round_trip() {
|
|||||||
let mut dst = vec![];
|
let mut dst = vec![];
|
||||||
rope.buf().read(&mut dst).unwrap();
|
rope.buf().read(&mut dst).unwrap();
|
||||||
|
|
||||||
assert_eq!(b"zomg", dst);
|
assert_eq!(b"zomg", &dst[..]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in New Issue
Block a user