Tags: factorize get_index unsafe code

This commit is contained in:
François Laignel 2018-07-09 21:44:19 +02:00 committed by Sebastian Dröge
parent 0b9edee8d7
commit 7ca54cf1c5

View file

@ -264,19 +264,15 @@ impl TagListRef {
} }
pub fn get_index<'a, T: Tag<'a>>(&'a self, idx: u32) -> Option<&'a TypedValue<T::TagType>> { pub fn get_index<'a, T: Tag<'a>>(&'a self, idx: u32) -> Option<&'a TypedValue<T::TagType>> {
unsafe { self.get_index_generic(T::tag_name(), idx)
let value = ffi::gst_tag_list_get_value_index( .and_then(|value| unsafe {
self.as_ptr(), let value = value.to_glib_none().0;
T::tag_name().to_glib_none().0, if (*value).g_type != T::TagType::static_type().to_glib() {
idx, return None;
); }
if value.is_null() || (*value).g_type != T::TagType::static_type().to_glib() { Some(&*(value as *const TypedValue<T::TagType>))
return None; })
}
Some(&*(value as *const TypedValue<T::TagType>))
}
} }
pub fn get_index_generic<'a>(&'a self, tag_name: &str, idx: u32) -> Option<&'a SendValue> { pub fn get_index_generic<'a>(&'a self, tag_name: &str, idx: u32) -> Option<&'a SendValue> {