Skip to content

Commit 167afbb

Browse files
committed
fix: bug in impl PartialEq for Extensions
1 parent 3c4a843 commit 167afbb

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

object_store/src/extensions.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,15 @@ pub struct Extensions {
3232

3333
impl PartialEq for Extensions {
3434
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;
4337
}
4438

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+
})
4644
}
4745
}
4846

@@ -166,13 +164,20 @@ mod test {
166164
exts1.set_ext_wrapped(String::from("meow"));
167165

168166
let mut exts2 = Extensions::default();
169-
exts2.set_ext_wrapped(1);
167+
exts2.set_ext_wrapped(0);
170168

171169
assert_ne!(
172170
exts1, exts2,
173171
"two different Extensions cannot be equal if they don't carry the same types"
174172
);
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+
);
175179
}
180+
176181
#[test]
177182
fn equality_ext_wrapper() {
178183
let mut exts1 = Extensions::default();

0 commit comments

Comments
 (0)