Skip to content

Commit 4c43693

Browse files
kawadakksdroege
authored andcommitted
glib: Compare lengths in <StrVRef as PartialEq<[&str]>>::eq
1 parent 1cfeb9c commit 4c43693

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

glib/src/collections/strv.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,6 +1466,10 @@ impl std::hash::Hash for StrVRef {
14661466

14671467
impl PartialEq<[&'_ str]> for StrVRef {
14681468
fn eq(&self, other: &[&'_ str]) -> bool {
1469+
if self.len() != other.len() {
1470+
return false;
1471+
}
1472+
14691473
for (a, b) in Iterator::zip(self.iter(), other.iter()) {
14701474
if a != b {
14711475
return false;
@@ -1847,4 +1851,16 @@ mod test {
18471851
assert!((*strv.as_ptr().add(strv.len())).is_null());
18481852
}
18491853
}
1854+
1855+
#[test]
1856+
fn test_strv_ref_eq_str_slice() {
1857+
let strv = StrV::from(&[crate::gstr!("a")][..]);
1858+
let strv_ref: &StrVRef = strv.as_ref();
1859+
1860+
// Test `impl PartialEq<[&'_ str]> for StrVRef`
1861+
assert_eq!(strv_ref, &["a"][..]);
1862+
assert_ne!(strv_ref, &[][..]);
1863+
assert_ne!(strv_ref, &["a", "b"][..]);
1864+
assert_ne!(strv_ref, &["b"][..]);
1865+
}
18501866
}

0 commit comments

Comments
 (0)