For borrowing Structures, StructureRef has to be used

Otherwise DerefMut would have to go away.
This commit is contained in:
Sebastian Dröge 2017-07-11 00:08:56 +03:00
parent c0707bed94
commit 8f49779329

View file

@ -20,7 +20,7 @@ use glib::value::{Value, ToValue, FromValueOptional};
use ffi; use ffi;
use glib_ffi; use glib_ffi;
pub struct Structure(*mut StructureRef, PhantomData<StructureRef>, bool); pub struct Structure(*mut StructureRef, PhantomData<StructureRef>);
impl Structure { impl Structure {
pub fn new_empty(name: &str) -> Structure { pub fn new_empty(name: &str) -> Structure {
@ -28,7 +28,6 @@ impl Structure {
Structure( Structure(
unsafe { ffi::gst_structure_new_empty(name.to_glib_none().0) as *mut StructureRef }, unsafe { ffi::gst_structure_new_empty(name.to_glib_none().0) as *mut StructureRef },
PhantomData, PhantomData,
false,
) )
} }
@ -50,7 +49,7 @@ impl Structure {
if structure.is_null() { if structure.is_null() {
None None
} else { } else {
Some(Structure(structure as *mut StructureRef, PhantomData, false)) Some(Structure(structure as *mut StructureRef, PhantomData))
} }
} }
} }
@ -94,17 +93,14 @@ impl Clone for Structure {
Structure( Structure(
unsafe { ffi::gst_structure_copy(&(*self.0).0) as *mut StructureRef }, unsafe { ffi::gst_structure_copy(&(*self.0).0) as *mut StructureRef },
PhantomData, PhantomData,
false,
) )
} }
} }
impl Drop for Structure { impl Drop for Structure {
fn drop(&mut self) { fn drop(&mut self) {
if !self.2 {
unsafe { ffi::gst_structure_free(&mut (*self.0).0) } unsafe { ffi::gst_structure_free(&mut (*self.0).0) }
} }
}
} }
impl fmt::Debug for Structure { impl fmt::Debug for Structure {
@ -146,7 +142,6 @@ impl ToOwned for StructureRef {
Structure( Structure(
unsafe { ffi::gst_structure_copy(&self.0) as *mut StructureRef }, unsafe { ffi::gst_structure_copy(&self.0) as *mut StructureRef },
PhantomData, PhantomData,
false,
) )
} }
} }
@ -200,7 +195,6 @@ impl FromGlibPtrNone<*const ffi::GstStructure> for Structure {
Structure( Structure(
ffi::gst_structure_copy(ptr) as *mut StructureRef, ffi::gst_structure_copy(ptr) as *mut StructureRef,
PhantomData, PhantomData,
false,
) )
} }
} }
@ -210,7 +204,6 @@ impl FromGlibPtrNone<*mut ffi::GstStructure> for Structure {
Structure( Structure(
ffi::gst_structure_copy(ptr) as *mut StructureRef, ffi::gst_structure_copy(ptr) as *mut StructureRef,
PhantomData, PhantomData,
false,
) )
} }
} }
@ -220,7 +213,6 @@ impl FromGlibPtrFull<*const ffi::GstStructure> for Structure {
Structure( Structure(
ptr as *mut StructureRef, ptr as *mut StructureRef,
PhantomData, PhantomData,
false,
) )
} }
} }
@ -230,27 +222,6 @@ impl FromGlibPtrFull<*mut ffi::GstStructure> for Structure {
Structure( Structure(
ptr as *mut StructureRef, ptr as *mut StructureRef,
PhantomData, PhantomData,
false,
)
}
}
impl FromGlibPtrBorrow<*const ffi::GstStructure> for Structure {
unsafe fn from_glib_borrow(ptr: *const ffi::GstStructure) -> Self {
Structure(
ptr as *mut StructureRef,
PhantomData,
true,
)
}
}
impl FromGlibPtrBorrow<*mut ffi::GstStructure> for Structure {
unsafe fn from_glib_borrow(ptr: *mut ffi::GstStructure) -> Self {
Structure(
ptr as *mut StructureRef,
PhantomData,
true,
) )
} }
} }