gstreamer/
static_pad_template.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::{ffi::CStr, fmt, marker::PhantomData, ptr};
4
5use glib::{prelude::*, translate::*};
6
7use crate::{Caps, PadTemplate, ffi};
8
9#[doc(alias = "GstStaticPadTemplate")]
10#[derive(Clone, Copy)]
11pub struct StaticPadTemplate(ptr::NonNull<ffi::GstStaticPadTemplate>);
12
13impl StaticPadTemplate {
14    #[doc(alias = "gst_static_pad_template_get")]
15    #[inline]
16    pub fn get(&self) -> PadTemplate {
17        unsafe { from_glib_full(ffi::gst_static_pad_template_get(self.0.as_ptr())) }
18    }
19
20    #[doc(alias = "get_caps")]
21    #[doc(alias = "gst_static_pad_template_get_caps")]
22    #[inline]
23    pub fn caps(&self) -> Caps {
24        unsafe { from_glib_full(ffi::gst_static_pad_template_get_caps(self.0.as_ptr())) }
25    }
26
27    #[inline]
28    pub fn name_template<'a>(&self) -> &'a str {
29        unsafe {
30            CStr::from_ptr(self.0.as_ref().name_template)
31                .to_str()
32                .unwrap()
33        }
34    }
35
36    #[inline]
37    pub fn direction(&self) -> crate::PadDirection {
38        unsafe { from_glib(self.0.as_ref().direction) }
39    }
40
41    #[inline]
42    pub fn presence(&self) -> crate::PadPresence {
43        unsafe { from_glib(self.0.as_ref().presence) }
44    }
45}
46
47unsafe impl glib::translate::TransparentPtrType for StaticPadTemplate {}
48
49unsafe impl Send for StaticPadTemplate {}
50unsafe impl Sync for StaticPadTemplate {}
51
52impl fmt::Debug for StaticPadTemplate {
53    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
54        f.debug_struct("StaticPadTemplate")
55            .field("name_template", &unsafe {
56                CStr::from_ptr(self.0.as_ref().name_template).to_str()
57            })
58            .field("direction", &unsafe {
59                from_glib::<_, crate::PadDirection>(self.0.as_ref().direction)
60            })
61            .field("presence", &unsafe {
62                from_glib::<_, crate::PadPresence>(self.0.as_ref().presence)
63            })
64            .field("static_caps", &unsafe {
65                from_glib_none::<_, crate::StaticCaps>(&self.0.as_ref().static_caps as *const _)
66            })
67            .finish()
68    }
69}
70
71impl glib::types::StaticType for StaticPadTemplate {
72    #[inline]
73    fn static_type() -> glib::types::Type {
74        unsafe { glib::translate::from_glib(ffi::gst_static_pad_template_get_type()) }
75    }
76}
77
78impl glib::value::ValueType for StaticPadTemplate {
79    type Type = Self;
80}
81
82#[doc(hidden)]
83unsafe impl<'a> glib::value::FromValue<'a> for StaticPadTemplate {
84    type Checker = glib::value::GenericValueTypeOrNoneChecker<Self>;
85
86    #[inline]
87    unsafe fn from_value(value: &'a glib::Value) -> Self {
88        unsafe {
89            skip_assert_initialized!();
90            from_glib_none(glib::gobject_ffi::g_value_get_boxed(value.to_glib_none().0)
91                as *mut ffi::GstStaticPadTemplate)
92        }
93    }
94}
95
96#[doc(hidden)]
97impl glib::value::ToValue for StaticPadTemplate {
98    #[inline]
99    fn to_value(&self) -> glib::Value {
100        let mut value = glib::Value::for_value_type::<Self>();
101        unsafe {
102            glib::gobject_ffi::g_value_set_boxed(
103                value.to_glib_none_mut().0,
104                self.to_glib_none().0 as *mut _,
105            )
106        }
107        value
108    }
109
110    #[inline]
111    fn value_type(&self) -> glib::Type {
112        Self::static_type()
113    }
114}
115
116#[doc(hidden)]
117impl glib::value::ToValueOptional for StaticPadTemplate {
118    #[inline]
119    fn to_value_optional(s: Option<&Self>) -> glib::Value {
120        skip_assert_initialized!();
121        let mut value = glib::Value::for_value_type::<Self>();
122        unsafe {
123            glib::gobject_ffi::g_value_set_boxed(
124                value.to_glib_none_mut().0,
125                s.to_glib_none().0 as *mut _,
126            )
127        }
128        value
129    }
130}
131
132impl From<StaticPadTemplate> for glib::Value {
133    #[inline]
134    fn from(v: StaticPadTemplate) -> glib::Value {
135        skip_assert_initialized!();
136        glib::value::ToValue::to_value(&v)
137    }
138}
139
140#[doc(hidden)]
141impl glib::translate::GlibPtrDefault for StaticPadTemplate {
142    type GlibType = *mut ffi::GstStaticPadTemplate;
143}
144
145#[doc(hidden)]
146impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstStaticPadTemplate> for StaticPadTemplate {
147    type Storage = PhantomData<&'a StaticPadTemplate>;
148
149    #[inline]
150    fn to_glib_none(
151        &'a self,
152    ) -> glib::translate::Stash<'a, *const ffi::GstStaticPadTemplate, Self> {
153        glib::translate::Stash(self.0.as_ptr(), PhantomData)
154    }
155
156    fn to_glib_full(&self) -> *const ffi::GstStaticPadTemplate {
157        unimplemented!()
158    }
159}
160
161#[doc(hidden)]
162impl glib::translate::FromGlibPtrNone<*const ffi::GstStaticPadTemplate> for StaticPadTemplate {
163    #[inline]
164    unsafe fn from_glib_none(ptr: *const ffi::GstStaticPadTemplate) -> Self {
165        unsafe {
166            debug_assert!(!ptr.is_null());
167            StaticPadTemplate(ptr::NonNull::new_unchecked(ptr as *mut _))
168        }
169    }
170}
171
172#[doc(hidden)]
173impl glib::translate::FromGlibPtrNone<*mut ffi::GstStaticPadTemplate> for StaticPadTemplate {
174    #[inline]
175    unsafe fn from_glib_none(ptr: *mut ffi::GstStaticPadTemplate) -> Self {
176        unsafe {
177            debug_assert!(!ptr.is_null());
178            StaticPadTemplate(ptr::NonNull::new_unchecked(ptr))
179        }
180    }
181}
182
183#[doc(hidden)]
184impl glib::translate::FromGlibPtrBorrow<*mut ffi::GstStaticPadTemplate> for StaticPadTemplate {
185    #[inline]
186    unsafe fn from_glib_borrow(ptr: *mut ffi::GstStaticPadTemplate) -> Borrowed<Self> {
187        unsafe {
188            debug_assert!(!ptr.is_null());
189            Borrowed::new(StaticPadTemplate(ptr::NonNull::new_unchecked(ptr)))
190        }
191    }
192}
193
194#[doc(hidden)]
195impl glib::translate::FromGlibPtrFull<*mut ffi::GstStaticPadTemplate> for StaticPadTemplate {
196    unsafe fn from_glib_full(_ptr: *mut ffi::GstStaticPadTemplate) -> Self {
197        unimplemented!();
198    }
199}