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