File tree 1 file changed +15
-10
lines changed
1 file changed +15
-10
lines changed Original file line number Diff line number Diff line change @@ -32,17 +32,15 @@ pub struct Extensions {
32
32
33
33
impl PartialEq for Extensions {
34
34
fn eq ( & self , other : & Self ) -> bool {
35
- for ( k, v) in & self . inner {
36
- if let Some ( ov) = other. inner . get ( & k) {
37
- if !v. clone ( ) . partial_eq ( ov. clone ( ) . as_any ( ) ) {
38
- return false ;
39
- }
40
- } else {
41
- return false ;
42
- }
35
+ if self . inner . len ( ) != other. inner . len ( ) {
36
+ return false ;
43
37
}
44
38
45
- true
39
+ self . inner . iter ( ) . all ( |( key, value) | {
40
+ other. inner . get ( key) . map_or ( false , |other| {
41
+ value. clone ( ) . partial_eq ( other. clone ( ) . as_any ( ) )
42
+ } )
43
+ } )
46
44
}
47
45
}
48
46
@@ -166,13 +164,20 @@ mod test {
166
164
exts1. set_ext_wrapped ( String :: from ( "meow" ) ) ;
167
165
168
166
let mut exts2 = Extensions :: default ( ) ;
169
- exts2. set_ext_wrapped ( 1 ) ;
167
+ exts2. set_ext_wrapped ( 0 ) ;
170
168
171
169
assert_ne ! (
172
170
exts1, exts2,
173
171
"two different Extensions cannot be equal if they don't carry the same types"
174
172
) ;
173
+
174
+ // validate the PartialEq impl is commutative
175
+ assert_ne ! (
176
+ exts2, exts1,
177
+ "two different Extensions cannot be equal if they don't carry the same types"
178
+ ) ;
175
179
}
180
+
176
181
#[ test]
177
182
fn equality_ext_wrapper ( ) {
178
183
let mut exts1 = Extensions :: default ( ) ;
You can’t perform that action at this time.
0 commit comments