From 908078dcf0d60bb851a801c32e422bb43a02ed8d Mon Sep 17 00:00:00 2001 From: Andrew Paseltiner Date: Thu, 10 Mar 2016 19:05:18 -0500 Subject: [PATCH] Simplify impls --- src/lib.rs | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a034461..548202f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -133,33 +133,21 @@ impl Extend for BitSet { impl PartialOrd for BitSet { #[inline] fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) + self.iter().partial_cmp(other) } } impl Ord for BitSet { #[inline] fn cmp(&self, other: &Self) -> Ordering { - let mut a = self.iter(); - let mut b = other.iter(); - loop { - match (a.next(), b.next()) { - (Some(x), Some(y)) => match x.cmp(&y) { - Ordering::Equal => {} - otherwise => return otherwise, - }, - (None, None) => return Ordering::Equal, - (None, _) => return Ordering::Less, - (_, None) => return Ordering::Greater, - } - } + self.iter().cmp(other) } } impl PartialEq for BitSet { #[inline] fn eq(&self, other: &Self) -> bool { - self.cmp(other) == Ordering::Equal + self.iter().eq(other) } } @@ -796,16 +784,7 @@ impl BitSet { impl fmt::Debug for BitSet { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - try!(write!(fmt, "{{")); - let mut first = true; - for n in self { - if !first { - try!(write!(fmt, ", ")); - } - try!(write!(fmt, "{:?}", n)); - first = false; - } - write!(fmt, "}}") + fmt.debug_set().entries(self).finish() } } -- 2.44.0