diff options
| author | bors <bors@rust-lang.org> | 2014-03-23 08:36:51 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-03-23 08:36:51 -0700 |
| commit | 903e83889ade166bf62f1ee74df8bf8331ea17d1 (patch) | |
| tree | 2d2c838f7adc52628632948a8b37820c4f03ed75 /src/libcollections | |
| parent | cafb7ed6f671a0102c4df9abad43b747c00f5cdf (diff) | |
| parent | f6db0ef9464a17fa6e547e755b1b5dfa09af9499 (diff) | |
| download | rust-903e83889ade166bf62f1ee74df8bf8331ea17d1.tar.gz rust-903e83889ade166bf62f1ee74df8bf8331ea17d1.zip | |
auto merge of #13102 : huonw/rust/totaleq-deriving, r=thestinger
std: remove the `equals` method from `TotalEq`. `TotalEq` is now just an assertion about the `Eq` impl of a type (i.e. `==` is a total equality if a type implements `TotalEq`) so the extra method is just confusing. Also, a new method magically appeared as a hack to allow deriving to assert that the contents of a struct/enum are also TotalEq, because the deriving infrastructure makes it very hard to do anything but create a trait method. (You didn't hear about this horrible work-around from me :(.)
Diffstat (limited to 'src/libcollections')
| -rw-r--r-- | src/libcollections/btree.rs | 57 |
1 files changed, 13 insertions, 44 deletions
diff --git a/src/libcollections/btree.rs b/src/libcollections/btree.rs index 6411b6bc974..3f53ede6027 100644 --- a/src/libcollections/btree.rs +++ b/src/libcollections/btree.rs @@ -94,17 +94,12 @@ impl<K: Clone + TotalOrd, V: Clone> Clone for BTree<K, V> { impl<K: TotalOrd, V: TotalEq> Eq for BTree<K, V> { fn eq(&self, other: &BTree<K, V>) -> bool { - self.equals(other) - } -} - -impl<K: TotalOrd, V: TotalEq> TotalEq for BTree<K, V> { - ///Testing equality on BTrees by comparing the root. - fn equals(&self, other: &BTree<K, V>) -> bool { self.root.cmp(&other.root) == Equal } } +impl<K: TotalOrd, V: TotalEq> TotalEq for BTree<K, V> {} + impl<K: TotalOrd, V: TotalEq> Ord for BTree<K, V> { fn lt(&self, other: &BTree<K, V>) -> bool { self.cmp(other) == Less @@ -204,14 +199,6 @@ impl<K: Clone + TotalOrd, V: Clone> Clone for Node<K, V> { impl<K: TotalOrd, V: TotalEq> Eq for Node<K, V> { fn eq(&self, other: &Node<K, V>) -> bool { - self.equals(other) - } -} - -impl<K: TotalOrd, V: TotalEq> TotalEq for Node<K, V> { - ///Returns whether two nodes are equal based on the keys of each element. - ///Two nodes are equal if all of their keys are the same. - fn equals(&self, other: &Node<K, V>) -> bool{ match *self{ BranchNode(ref branch) => { if other.is_leaf() { @@ -232,6 +219,8 @@ impl<K: TotalOrd, V: TotalEq> TotalEq for Node<K, V> { } } +impl<K: TotalOrd, V: TotalEq> TotalEq for Node<K, V> {} + impl<K: TotalOrd, V: TotalEq> Ord for Node<K, V> { fn lt(&self, other: &Node<K, V>) -> bool { self.cmp(other) == Less @@ -405,16 +394,11 @@ impl<K: Clone + TotalOrd, V: Clone> Clone for Leaf<K, V> { impl<K: TotalOrd, V: TotalEq> Eq for Leaf<K, V> { fn eq(&self, other: &Leaf<K, V>) -> bool { - self.equals(other) + self.elts == other.elts } } -impl<K: TotalOrd, V: TotalEq> TotalEq for Leaf<K, V> { - ///Implementation of equals function for leaves that compares LeafElts. - fn equals(&self, other: &Leaf<K, V>) -> bool { - self.elts.equals(&other.elts) - } -} +impl<K: TotalOrd, V: TotalEq> TotalEq for Leaf<K, V> {} impl<K: TotalOrd, V: TotalEq> Ord for Leaf<K, V> { fn lt(&self, other: &Leaf<K, V>) -> bool { @@ -639,16 +623,11 @@ impl<K: Clone + TotalOrd, V: Clone> Clone for Branch<K, V> { impl<K: TotalOrd, V: TotalEq> Eq for Branch<K, V> { fn eq(&self, other: &Branch<K, V>) -> bool { - self.equals(other) + self.elts == other.elts } } -impl<K: TotalOrd, V: TotalEq> TotalEq for Branch<K, V> { - ///Equals function for Branches--compares all the elements in each branch - fn equals(&self, other: &Branch<K, V>) -> bool { - self.elts.equals(&other.elts) - } -} +impl<K: TotalOrd, V: TotalEq> TotalEq for Branch<K, V> {} impl<K: TotalOrd, V: TotalEq> Ord for Branch<K, V> { fn lt(&self, other: &Branch<K, V>) -> bool { @@ -712,16 +691,11 @@ impl<K: Clone + TotalOrd, V: Clone> Clone for LeafElt<K, V> { impl<K: TotalOrd, V: TotalEq> Eq for LeafElt<K, V> { fn eq(&self, other: &LeafElt<K, V>) -> bool { - self.equals(other) + self.key == other.key && self.value == other.value } } -impl<K: TotalOrd, V: TotalEq> TotalEq for LeafElt<K, V> { - ///TotalEq for LeafElts - fn equals(&self, other: &LeafElt<K, V>) -> bool { - self.key.equals(&other.key) && self.value.equals(&other.value) - } -} +impl<K: TotalOrd, V: TotalEq> TotalEq for LeafElt<K, V> {} impl<K: TotalOrd, V: TotalEq> Ord for LeafElt<K, V> { fn lt(&self, other: &LeafElt<K, V>) -> bool { @@ -766,16 +740,11 @@ impl<K: Clone + TotalOrd, V: Clone> Clone for BranchElt<K, V> { impl<K: TotalOrd, V: TotalEq> Eq for BranchElt<K, V>{ fn eq(&self, other: &BranchElt<K, V>) -> bool { - self.equals(other) + self.key == other.key && self.value == other.value } } -impl<K: TotalOrd, V: TotalEq> TotalEq for BranchElt<K, V>{ - ///TotalEq for BranchElts - fn equals(&self, other: &BranchElt<K, V>) -> bool { - self.key.equals(&other.key)&&self.value.equals(&other.value) - } -} +impl<K: TotalOrd, V: TotalEq> TotalEq for BranchElt<K, V>{} impl<K: TotalOrd, V: TotalEq> Ord for BranchElt<K, V> { fn lt(&self, other: &BranchElt<K, V>) -> bool { @@ -900,7 +869,7 @@ mod test_btree { fn btree_clone_test() { let b = BTree::new(1, ~"abc", 2); let b2 = b.clone(); - assert!(b.root.equals(&b2.root)) + assert!(b.root == b2.root) } //Tests the BTree's cmp() method when one node is "less than" another. |
