Skip to content

Commit ae0da09

Browse files
committed
strv: add contains()
1 parent 2d4c666 commit ae0da09

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

glib/src/collections/strv.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,19 @@ impl StrV {
864864
))
865865
})
866866
}
867+
868+
// rustdoc-stripper-ignore-next
869+
/// Checks whether the `StrV` contains the specified string
870+
#[inline]
871+
#[doc(alias = "g_strv_contains")]
872+
pub fn contains(&self, s: impl IntoGStr) -> bool {
873+
s.run_with_gstr(|s| unsafe {
874+
from_glib(ffi::g_strv_contains(
875+
self.ptr.as_ptr() as *const _,
876+
s.to_glib_none().0,
877+
))
878+
})
879+
}
867880
}
868881

869882
impl FromGlibContainer<*mut c_char, *mut *mut c_char> for StrV {
@@ -1474,4 +1487,17 @@ mod test {
14741487
assert_eq!(s, items);
14751488
});
14761489
}
1490+
1491+
#[test]
1492+
fn test_contains() {
1493+
let items = [
1494+
crate::gstr!("str1"),
1495+
crate::gstr!("str2"),
1496+
crate::gstr!("str3"),
1497+
];
1498+
1499+
let strv = StrV::from(&items[..]);
1500+
assert!(strv.contains("str2"));
1501+
assert!(!strv.contains("str4"));
1502+
}
14771503
}

0 commit comments

Comments
 (0)