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