From 635274752ba6ee0ebc7ee9b9f52736ffbf1a4ee3 Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Fri, 3 Apr 2015 22:46:10 +0200 Subject: [PATCH] Update for new blanket impl rules. --- src/lib.rs | 65 +++++++++++++++++++++++++++-------------------- test/test_rope.rs | 2 +- 2 files changed, 38 insertions(+), 29 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 68ac6d1..98336f7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -254,41 +254,50 @@ pub trait ByteStr : Clone + Sized + Send + Sync + Reflect + ToBytes + ops::Index } } -impl cmp::PartialEq for B1 { - fn eq(&self, other: &B2) -> bool { - if self.len() != other.len() { - 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] { +macro_rules! impl_parteq { + ($ty:ty) => { + impl cmp::PartialEq for $ty { + fn eq(&self, other: &B) -> bool { + if self.len() != other.len() { 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); - buf2.advance(len); + fn ne(&self, other: &B) -> bool { + 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 { ($ty:ty) => { impl cmp::Eq for $ty {} @@ -549,7 +558,7 @@ impl_write!(MutByteBuf); * */ -#[derive(Copy, Debug)] +#[derive(Copy, Clone, Debug)] pub enum BufError { Underflow, Overflow, diff --git a/test/test_rope.rs b/test/test_rope.rs index 1f30f10..30d711b 100644 --- a/test/test_rope.rs +++ b/test/test_rope.rs @@ -36,7 +36,7 @@ pub fn test_rope_round_trip() { let mut dst = vec![]; rope.buf().read(&mut dst).unwrap(); - assert_eq!(b"zomg", dst); + assert_eq!(b"zomg", &dst[..]); } #[test]