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