Minor cleanup

This commit is contained in:
Sebastian Dröge 2017-04-24 10:13:32 +01:00
parent 9b593136da
commit 139c9be958
3 changed files with 18 additions and 13 deletions

View file

@ -84,14 +84,22 @@ impl Caps {
pub fn get_structure(&self, idx: u32) -> Option<&Structure> {
unsafe {
let structure = gst::gst_caps_get_structure(self.as_ptr(), idx);
Structure::from_borrowed_ptr(structure as *const gst::GstStructure)
if structure.is_null() {
return None;
}
Some(Structure::from_borrowed_ptr(structure as *const gst::GstStructure))
}
}
pub fn get_mut_structure(&mut self, idx: u32) -> Option<&mut Structure> {
unsafe {
let structure = gst::gst_caps_get_structure(self.as_ptr(), idx);
Structure::from_borrowed_mut_ptr(structure as *mut gst::GstStructure)
if structure.is_null() {
return None;
}
Some(Structure::from_borrowed_mut_ptr(structure as *mut gst::GstStructure))
}
}

View file

@ -146,10 +146,12 @@ pub unsafe trait MiniObject
}
unsafe fn from_ptr<'a>(ptr: *const Self::PtrType) -> &'a Self {
assert!(!ptr.is_null());
&*(ptr as *const Self)
}
unsafe fn from_mut_ptr<'a>(ptr: *mut Self::PtrType) -> &'a mut Self {
assert!(!ptr.is_null());
&mut *(ptr as *mut Self)
}
}

View file

@ -141,21 +141,16 @@ impl ToOwned for Structure {
pub struct Structure(gst::GstStructure);
impl Structure {
pub unsafe fn from_borrowed_ptr<'a>(ptr: *const gst::GstStructure) -> Option<&'a Structure> {
if ptr.is_null() {
return None;
}
pub unsafe fn from_borrowed_ptr<'a>(ptr: *const gst::GstStructure) -> &'a Structure {
assert!(!ptr.is_null());
Some(&*(ptr as *mut Structure))
&*(ptr as *mut Structure)
}
pub unsafe fn from_borrowed_mut_ptr<'a>(ptr: *mut gst::GstStructure)
-> Option<&'a mut Structure> {
if ptr.is_null() {
return None;
}
pub unsafe fn from_borrowed_mut_ptr<'a>(ptr: *mut gst::GstStructure) -> &'a mut Structure {
assert!(!ptr.is_null());
Some(&mut *(ptr as *mut Structure))
&mut *(ptr as *mut Structure)
}
pub fn to_string(&self) -> String {