1use std::{fmt, marker::PhantomData, ptr};
4
5use glib::{prelude::*, translate::*};
6
7use crate::{Caps, ffi};
8
9#[doc(alias = "GstStaticCaps")]
13#[derive(Clone, Copy)]
14pub struct StaticCaps(ptr::NonNull<ffi::GstStaticCaps>);
15
16impl StaticCaps {
17 #[doc(alias = "gst_static_caps_get")]
25 #[inline]
26 pub fn get(&self) -> Caps {
27 unsafe { from_glib_full(ffi::gst_static_caps_get(self.0.as_ptr())) }
28 }
29}
30
31unsafe impl Send for StaticCaps {}
32unsafe impl Sync for StaticCaps {}
33
34impl fmt::Debug for StaticCaps {
35 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
36 f.debug_struct("StaticCaps")
37 .field("str", &unsafe {
38 glib::GStr::from_ptr(self.0.as_ref().string)
39 })
40 .finish()
41 }
42}
43
44impl StaticType for StaticCaps {
45 #[inline]
46 fn static_type() -> glib::types::Type {
47 unsafe { glib::translate::from_glib(ffi::gst_static_caps_get_type()) }
48 }
49}
50
51impl glib::value::ValueType for StaticCaps {
52 type Type = Self;
53}
54
55unsafe impl glib::translate::TransparentPtrType for StaticCaps {}
56
57#[doc(hidden)]
58unsafe impl<'a> glib::value::FromValue<'a> for StaticCaps {
59 type Checker = glib::value::GenericValueTypeOrNoneChecker<Self>;
60
61 #[inline]
62 unsafe fn from_value(value: &'a glib::Value) -> Self {
63 unsafe {
64 skip_assert_initialized!();
65 from_glib_none(glib::gobject_ffi::g_value_get_boxed(value.to_glib_none().0)
66 as *mut ffi::GstStaticCaps)
67 }
68 }
69}
70
71#[doc(hidden)]
72impl glib::value::ToValue for StaticCaps {
73 #[inline]
74 fn to_value(&self) -> glib::Value {
75 let mut value = glib::Value::for_value_type::<Self>();
76 unsafe {
77 glib::gobject_ffi::g_value_set_boxed(
78 value.to_glib_none_mut().0,
79 self.to_glib_none().0 as *mut _,
80 )
81 }
82 value
83 }
84
85 #[inline]
86 fn value_type(&self) -> glib::Type {
87 Self::static_type()
88 }
89}
90
91impl From<StaticCaps> for glib::Value {
92 #[inline]
93 fn from(v: StaticCaps) -> glib::Value {
94 skip_assert_initialized!();
95 glib::value::ToValue::to_value(&v)
96 }
97}
98
99#[doc(hidden)]
100impl glib::value::ToValueOptional for StaticCaps {
101 #[inline]
102 fn to_value_optional(s: Option<&Self>) -> glib::Value {
103 skip_assert_initialized!();
104 let mut value = glib::Value::for_value_type::<Self>();
105 unsafe {
106 glib::gobject_ffi::g_value_set_boxed(
107 value.to_glib_none_mut().0,
108 s.to_glib_none().0 as *mut _,
109 )
110 }
111 value
112 }
113}
114
115#[doc(hidden)]
116impl glib::translate::GlibPtrDefault for StaticCaps {
117 type GlibType = *mut ffi::GstStaticCaps;
118}
119
120#[doc(hidden)]
121impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstStaticCaps> for StaticCaps {
122 type Storage = PhantomData<&'a StaticCaps>;
123
124 #[inline]
125 fn to_glib_none(&'a self) -> glib::translate::Stash<'a, *const ffi::GstStaticCaps, Self> {
126 glib::translate::Stash(self.0.as_ptr(), PhantomData)
127 }
128
129 fn to_glib_full(&self) -> *const ffi::GstStaticCaps {
130 unimplemented!()
131 }
132}
133
134#[doc(hidden)]
135impl glib::translate::FromGlibPtrNone<*const ffi::GstStaticCaps> for StaticCaps {
136 #[inline]
137 unsafe fn from_glib_none(ptr: *const ffi::GstStaticCaps) -> Self {
138 unsafe {
139 debug_assert!(!ptr.is_null());
140 StaticCaps(ptr::NonNull::new_unchecked(ptr as *mut _))
141 }
142 }
143}
144
145#[doc(hidden)]
146impl glib::translate::FromGlibPtrNone<*mut ffi::GstStaticCaps> for StaticCaps {
147 #[inline]
148 unsafe fn from_glib_none(ptr: *mut ffi::GstStaticCaps) -> Self {
149 unsafe {
150 debug_assert!(!ptr.is_null());
151 StaticCaps(ptr::NonNull::new_unchecked(ptr))
152 }
153 }
154}
155
156#[doc(hidden)]
157impl glib::translate::FromGlibPtrBorrow<*mut ffi::GstStaticCaps> for StaticCaps {
158 #[inline]
159 unsafe fn from_glib_borrow(ptr: *mut ffi::GstStaticCaps) -> Borrowed<Self> {
160 unsafe {
161 debug_assert!(!ptr.is_null());
162 Borrowed::new(StaticCaps(ptr::NonNull::new_unchecked(ptr)))
163 }
164 }
165}
166
167#[doc(hidden)]
168impl glib::translate::FromGlibPtrFull<*mut ffi::GstStaticCaps> for StaticCaps {
169 #[inline]
170 unsafe fn from_glib_full(_ptr: *mut ffi::GstStaticCaps) -> Self {
171 unimplemented!();
172 }
173}