From: Andrew Paseltiner Date: Fri, 11 Mar 2016 00:05:18 +0000 (-0500) Subject: Simplify impls X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=908078dcf0d60bb851a801c32e422bb43a02ed8d;p=bit-set.git Simplify impls --- 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() } }