From 7ca54cf1c576d7226cd7edb62b95e61ebb3f2890 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Laignel?= Date: Mon, 9 Jul 2018 21:44:19 +0200 Subject: [PATCH] Tags: factorize `get_index` unsafe code --- gstreamer/src/tags.rs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/gstreamer/src/tags.rs b/gstreamer/src/tags.rs index 6aa9c1cd6..f7c8e688c 100644 --- a/gstreamer/src/tags.rs +++ b/gstreamer/src/tags.rs @@ -264,19 +264,15 @@ impl TagListRef { } pub fn get_index<'a, T: Tag<'a>>(&'a self, idx: u32) -> Option<&'a TypedValue> { - unsafe { - let value = ffi::gst_tag_list_get_value_index( - self.as_ptr(), - T::tag_name().to_glib_none().0, - idx, - ); + self.get_index_generic(T::tag_name(), idx) + .and_then(|value| unsafe { + let value = value.to_glib_none().0; + if (*value).g_type != T::TagType::static_type().to_glib() { + return None; + } - if value.is_null() || (*value).g_type != T::TagType::static_type().to_glib() { - return None; - } - - Some(&*(value as *const TypedValue)) - } + Some(&*(value as *const TypedValue)) + }) } pub fn get_index_generic<'a>(&'a self, tag_name: &str, idx: u32) -> Option<&'a SendValue> {