Make use of the new TransparentType / TransparentPtrType traits

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1178>
This commit is contained in:
Sebastian Dröge 2023-01-02 19:03:08 +02:00
parent aeca82c095
commit 882513d33a
15 changed files with 47 additions and 5 deletions

View file

@ -42,6 +42,7 @@ impl IntoGlib for AudioEndianness {
}
#[doc(alias = "GstAudioFormatInfo")]
#[derive(Copy, Clone)]
pub struct AudioFormatInfo(&'static ffi::GstAudioFormatInfo);
impl AudioFormatInfo {
@ -379,6 +380,9 @@ impl glib::translate::GlibPtrDefault for AudioFormatInfo {
type GlibType = *mut ffi::GstAudioFormatInfo;
}
#[doc(hidden)]
unsafe impl glib::translate::TransparentPtrType for AudioFormatInfo {}
#[doc(hidden)]
impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstAudioFormatInfo> for AudioFormatInfo {
type Storage = PhantomData<&'a Self>;

View file

@ -512,6 +512,9 @@ impl glib::translate::GlibPtrDefault for VideoFormatInfo {
type GlibType = *mut ffi::GstVideoFormatInfo;
}
#[doc(hidden)]
unsafe impl glib::translate::TransparentPtrType for VideoFormatInfo {}
#[doc(hidden)]
impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstVideoFormatInfo> for VideoFormatInfo {
type Storage = PhantomData<&'a Self>;

View file

@ -351,6 +351,11 @@ macro_rules! generic_impl {
type GlibType = *mut ffi::GstVideoTimeCode;
}
#[doc(hidden)]
unsafe impl TransparentType for $name {
type GlibType = ffi::GstVideoTimeCode;
}
#[doc(hidden)]
impl<'a> ToGlibPtr<'a, *const ffi::GstVideoTimeCode> for $name {
type Storage = PhantomData<&'a Self>;

View file

@ -136,6 +136,11 @@ impl GlibPtrDefault for VideoTimeCodeInterval {
type GlibType = *mut ffi::GstVideoTimeCodeInterval;
}
#[doc(hidden)]
unsafe impl TransparentType for VideoTimeCodeInterval {
type GlibType = ffi::GstVideoTimeCodeInterval;
}
#[doc(hidden)]
impl<'a> ToGlibPtr<'a, *const ffi::GstVideoTimeCodeInterval> for VideoTimeCodeInterval {
type Storage = PhantomData<&'a Self>;

View file

@ -300,6 +300,8 @@ impl GlibPtrDefault for CapsFeatures {
type GlibType = *mut ffi::GstCapsFeatures;
}
unsafe impl TransparentPtrType for CapsFeatures {}
#[repr(transparent)]
#[doc(alias = "GstCapsFeatures")]
pub struct CapsFeaturesRef(ffi::GstCapsFeatures);

View file

@ -996,7 +996,7 @@ pub unsafe trait ElementClassExt {
unsafe {
let klass = self as *const _ as *const ffi::GstElementClass;
glib::List::from_glib_none_static(ffi::gst_element_class_get_pad_template_list(
glib::List::from_glib_none(ffi::gst_element_class_get_pad_template_list(
klass as *mut _,
))
}

View file

@ -101,9 +101,9 @@ impl ElementFactory {
#[doc(alias = "get_static_pad_templates")]
pub fn static_pad_templates(&self) -> glib::List<StaticPadTemplate> {
unsafe {
glib::List::from_glib_none_static(ffi::gst_element_factory_get_static_pad_templates(
glib::List::from_glib_none(ffi::gst_element_factory_get_static_pad_templates(
self.to_glib_none().0,
) as *mut _)
))
}
}

View file

@ -568,6 +568,9 @@ impl<T> glib::translate::GlibPtrDefault for Iterator<T> {
type GlibType = *mut ffi::GstIterator;
}
#[doc(hidden)]
unsafe impl<T: StaticType + 'static> TransparentPtrType for Iterator<T> {}
#[doc(hidden)]
impl<'a, T: 'static> glib::translate::ToGlibPtr<'a, *const ffi::GstIterator> for Iterator<T> {
type Storage = PhantomData<&'a Iterator<T>>;

View file

@ -394,7 +394,7 @@ impl DebugCategory {
#[doc(alias = "get_all_categories")]
#[doc(alias = "gst_debug_get_all_categories")]
pub fn all_categories() -> glib::SList<DebugCategory> {
unsafe { glib::SList::from_glib_container_static(ffi::gst_debug_get_all_categories()) }
unsafe { glib::SList::from_glib_container(ffi::gst_debug_get_all_categories()) }
}
#[cfg(any(feature = "v1_18", feature = "dox"))]
@ -438,6 +438,8 @@ impl GlibPtrDefault for DebugCategory {
type GlibType = *mut ffi::GstDebugCategory;
}
unsafe impl TransparentPtrType for DebugCategory {}
impl FromGlibPtrNone<*mut ffi::GstDebugCategory> for DebugCategory {
unsafe fn from_glib_none(ptr: *mut ffi::GstDebugCategory) -> Self {
assert!(!ptr.is_null());
@ -1216,7 +1218,9 @@ mod tests {
fn all() {
crate::init().unwrap();
assert!(DebugCategory::all_categories().any(|c| c.name() == "GST_PERFORMANCE"));
assert!(DebugCategory::all_categories()
.iter()
.any(|c| c.name() == "GST_PERFORMANCE"));
}
#[test]

View file

@ -387,6 +387,8 @@ macro_rules! mini_object_wrapper (
type GlibType = *mut $ffi_name;
}
unsafe impl $crate::glib::translate::TransparentPtrType for $name {}
impl $ref_name {
pub fn as_ptr(&self) -> *const $ffi_name {
self as *const Self as *const $ffi_name

View file

@ -656,6 +656,11 @@ impl<T: FormattedValueIntrinsic> glib::translate::GlibPtrDefault for FormattedSe
type GlibType = *mut ffi::GstSegment;
}
#[doc(hidden)]
unsafe impl<T: FormattedValueIntrinsic> TransparentType for FormattedSegment<T> {
type GlibType = ffi::GstSegment;
}
#[doc(hidden)]
impl<'a, T: FormattedValueIntrinsic> glib::translate::ToGlibPtr<'a, *const ffi::GstSegment>
for FormattedSegment<T>

View file

@ -11,6 +11,7 @@ use std::marker::PhantomData;
use std::ptr;
#[doc(alias = "GstStaticCaps")]
#[derive(Clone, Copy)]
pub struct StaticCaps(ptr::NonNull<ffi::GstStaticCaps>);
impl StaticCaps {
@ -43,6 +44,8 @@ impl glib::value::ValueType for StaticCaps {
type Type = Self;
}
unsafe impl glib::translate::TransparentPtrType for StaticCaps {}
#[doc(hidden)]
unsafe impl<'a> glib::value::FromValue<'a> for StaticCaps {
type Checker = glib::value::GenericValueTypeOrNoneChecker<Self>;

View file

@ -12,6 +12,7 @@ use std::marker::PhantomData;
use std::ptr;
#[doc(alias = "GstStaticPadTemplate")]
#[derive(Clone, Copy)]
pub struct StaticPadTemplate(ptr::NonNull<ffi::GstStaticPadTemplate>);
impl StaticPadTemplate {
@ -43,6 +44,8 @@ impl StaticPadTemplate {
}
}
unsafe impl glib::translate::TransparentPtrType for StaticPadTemplate {}
unsafe impl Send for StaticPadTemplate {}
unsafe impl Sync for StaticPadTemplate {}

View file

@ -368,6 +368,8 @@ impl GlibPtrDefault for Structure {
type GlibType = *mut ffi::GstStructure;
}
unsafe impl TransparentPtrType for Structure {}
#[repr(transparent)]
#[doc(alias = "GstStructure")]
pub struct StructureRef(ffi::GstStructure);

View file

@ -254,6 +254,7 @@ mod tests {
crate::init().unwrap();
let xml_factory = TypeFindFactory::factories()
.into_iter()
.find(|f| {
f.caps()
.map(|c| {