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::{translate::*, StaticType};
6
7use crate::{Caps, PadTemplate};
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&mut DebugStruct<'_, '_>.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(name:"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(val: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 skip_assert_initialized!();
89 from_glib_none(ptr:glib::gobject_ffi::g_value_get_boxed(value.to_glib_none().0)
90 as *mut ffi::GstStaticPadTemplate)
91 }
92}
93
94#[doc(hidden)]
95impl glib::value::ToValue for StaticPadTemplate {
96 #[inline]
97 fn to_value(&self) -> glib::Value {
98 let mut value: Value = glib::Value::for_value_type::<Self>();
99 unsafe {
100 glib::gobject_ffi::g_value_set_boxed(
101 value:value.to_glib_none_mut().0,
102 self.to_glib_none().0 as *mut _,
103 )
104 }
105 value
106 }
107
108 #[inline]
109 fn value_type(&self) -> glib::Type {
110 Self::static_type()
111 }
112}
113
114#[doc(hidden)]
115impl glib::value::ToValueOptional for StaticPadTemplate {
116 #[inline]
117 fn to_value_optional(s: Option<&Self>) -> glib::Value {
118 skip_assert_initialized!();
119 let mut value: Value = glib::Value::for_value_type::<Self>();
120 unsafe {
121 glib::gobject_ffi::g_value_set_boxed(
122 value:value.to_glib_none_mut().0,
123 v_boxed:s.to_glib_none().0 as *mut _,
124 )
125 }
126 value
127 }
128}
129
130impl From<StaticPadTemplate> for glib::Value {
131 #[inline]
132 fn from(v: StaticPadTemplate) -> glib::Value {
133 skip_assert_initialized!();
134 glib::value::ToValue::to_value(&v)
135 }
136}
137
138#[doc(hidden)]
139impl glib::translate::GlibPtrDefault for StaticPadTemplate {
140 type GlibType = *mut ffi::GstStaticPadTemplate;
141}
142
143#[doc(hidden)]
144impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstStaticPadTemplate> for StaticPadTemplate {
145 type Storage = PhantomData<&'a StaticPadTemplate>;
146
147 #[inline]
148 fn to_glib_none(
149 &'a self,
150 ) -> glib::translate::Stash<'a, *const ffi::GstStaticPadTemplate, Self> {
151 glib::translate::Stash(self.0.as_ptr(), PhantomData)
152 }
153
154 fn to_glib_full(&self) -> *const ffi::GstStaticPadTemplate {
155 unimplemented!()
156 }
157}
158
159#[doc(hidden)]
160impl glib::translate::FromGlibPtrNone<*const ffi::GstStaticPadTemplate> for StaticPadTemplate {
161 #[inline]
162 unsafe fn from_glib_none(ptr: *const ffi::GstStaticPadTemplate) -> Self {
163 debug_assert!(!ptr.is_null());
164 StaticPadTemplate(ptr::NonNull::new_unchecked(ptr as *mut _))
165 }
166}
167
168#[doc(hidden)]
169impl glib::translate::FromGlibPtrNone<*mut ffi::GstStaticPadTemplate> for StaticPadTemplate {
170 #[inline]
171 unsafe fn from_glib_none(ptr: *mut ffi::GstStaticPadTemplate) -> Self {
172 debug_assert!(!ptr.is_null());
173 StaticPadTemplate(ptr::NonNull::new_unchecked(ptr))
174 }
175}
176
177#[doc(hidden)]
178impl glib::translate::FromGlibPtrBorrow<*mut ffi::GstStaticPadTemplate> for StaticPadTemplate {
179 #[inline]
180 unsafe fn from_glib_borrow(ptr: *mut ffi::GstStaticPadTemplate) -> Borrowed<Self> {
181 debug_assert!(!ptr.is_null());
182 Borrowed::new(val:StaticPadTemplate(ptr::NonNull::new_unchecked(ptr)))
183 }
184}
185
186#[doc(hidden)]
187impl glib::translate::FromGlibPtrFull<*mut ffi::GstStaticPadTemplate> for StaticPadTemplate {
188 unsafe fn from_glib_full(_ptr: *mut ffi::GstStaticPadTemplate) -> Self {
189 unimplemented!();
190 }
191}
192