1use glib::translate::*;
2use std::mem;
3use std::ptr;
4
5#[repr(C)]
6#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
7pub struct MaterialLayer(ffi::CoglMaterialLayer);
8
9impl GlibPtrDefault for MaterialLayer {
10 type GlibType = ffi::CoglMaterialLayer;
11}
12
13#[doc(hidden)]
14impl Uninitialized for MaterialLayer {
15 #[inline]
16 unsafe fn uninitialized() -> Self {
17 mem::zeroed()
18 }
19}
20
21impl<'a> ToGlibPtr<'a, ffi::CoglMaterialLayer> for MaterialLayer {
22 type Storage = ();
23
24 #[inline]
25 fn to_glib_none(&self) -> Stash<'a, ffi::CoglMaterialLayer, MaterialLayer> {
26 Stash(self.0, ())
27 }
28}
29
30impl<'a> ToGlibPtrMut<'a, *mut ffi::CoglMaterialLayer> for MaterialLayer {
31 type Storage = ();
32
33 #[inline]
34 fn to_glib_none_mut(&'a mut self) -> StashMut<'a, *mut ffi::CoglMaterialLayer, MaterialLayer> {
35 StashMut(&mut self.0, ())
36 }
37}
38
39impl<'a> ToGlibContainerFromSlice<'a, *mut ffi::CoglMaterialLayer> for &'a MaterialLayer {
40 type Storage = (
41 Vec<Stash<'a, ffi::CoglMaterialLayer, &'a MaterialLayer>>,
42 Option<Vec<ffi::CoglMaterialLayer>>,
43 );
44
45 fn to_glib_none_from_slice(
46 t: &'a [&'a MaterialLayer],
47 ) -> (*mut ffi::CoglMaterialLayer, Self::Storage) {
48 let v: Vec<_> = t.iter().map(|s| s.to_glib_none()).collect();
49 let mut v_ptr: Vec<_> = v.iter().map(|s| s.0).collect();
50 v_ptr.push(ptr::null_mut());
51
52 (
53 v_ptr.as_ptr() as *mut ffi::CoglMaterialLayer,
54 (v, Some(v_ptr)),
55 )
56 }
57
58 fn to_glib_container_from_slice(
59 t: &'a [&'a MaterialLayer],
60 ) -> (*mut ffi::CoglMaterialLayer, Self::Storage) {
61 let v: Vec<_> = t.iter().map(|s| s.to_glib_none()).collect();
62
63 let v_ptr = unsafe {
64 let v_ptr =
65 glib_sys::g_malloc0(mem::size_of::<ffi::CoglMaterialLayer>() * (t.len() + 1))
66 as *mut ffi::CoglMaterialLayer;
67
68 for (i, s) in v.iter().enumerate() {
69 ptr::write(v_ptr.add(i), s.0);
70 }
71
72 v_ptr
73 };
74
75 (v_ptr, (v, None))
76 }
77
78 fn to_glib_full_from_slice(_: &[&'a MaterialLayer]) -> *mut ffi::CoglMaterialLayer {
79 unimplemented!()
80 }
81}
82
83impl<'a> ToGlibContainerFromSlice<'a, *const ffi::CoglMaterialLayer> for &'a MaterialLayer {
84 type Storage = (
85 Vec<Stash<'a, ffi::CoglMaterialLayer, &'a MaterialLayer>>,
86 Option<Vec<ffi::CoglMaterialLayer>>,
87 );
88
89 fn to_glib_none_from_slice(
90 t: &'a [&'a MaterialLayer],
91 ) -> (*const ffi::CoglMaterialLayer, Self::Storage) {
92 let v: Vec<_> = t.iter().map(|s| s.to_glib_none()).collect();
93 let mut v_ptr: Vec<_> = v.iter().map(|s| s.0).collect();
94 v_ptr.push(ptr::null_mut());
95
96 (
97 v_ptr.as_ptr() as *const ffi::CoglMaterialLayer,
98 (v, Some(v_ptr)),
99 )
100 }
101
102 fn to_glib_container_from_slice(
103 t: &'a [&'a MaterialLayer],
104 ) -> (*const ffi::CoglMaterialLayer, Self::Storage) {
105 let v: Vec<_> = t.iter().map(|s| s.to_glib_none()).collect();
106
107 let v_ptr = unsafe {
108 let v_ptr =
109 glib_sys::g_malloc0(mem::size_of::<ffi::CoglMaterialLayer>() * (t.len() + 1))
110 as *mut ffi::CoglMaterialLayer;
111
112 for (i, s) in v.iter().enumerate() {
113 ptr::write(v_ptr.add(i), s.0);
114 }
115
116 v_ptr as *const ffi::CoglMaterialLayer
117 };
118
119 (v_ptr, (v, None))
120 }
121
122 fn to_glib_full_from_slice(_: &[&'a MaterialLayer]) -> *const ffi::CoglMaterialLayer {
123 unimplemented!()
124 }
125}
126
127impl FromGlibPtrNone<ffi::CoglMaterialLayer> for MaterialLayer {
128 #[inline]
129 unsafe fn from_glib_none(ptr: ffi::CoglMaterialLayer) -> MaterialLayer {
130 MaterialLayer(ptr)
131 }
132}
133
134#[doc(hidden)]
135impl FromGlibPtrNone<*const ffi::CoglMaterialLayer> for MaterialLayer {
136 unsafe fn from_glib_none(ptr: *const ffi::CoglMaterialLayer) -> Self {
137 *(ptr as *const MaterialLayer)
138 }
139}
140
141#[doc(hidden)]
142impl FromGlibPtrNone<*mut ffi::CoglMaterialLayer> for MaterialLayer {
143 unsafe fn from_glib_none(ptr: *mut ffi::CoglMaterialLayer) -> Self {
144 *(ptr as *mut MaterialLayer)
145 }
146}
147
148impl FromGlibPtrBorrow<ffi::CoglMaterialLayer> for MaterialLayer {
149 #[inline]
150 unsafe fn from_glib_borrow(
151 ptr: ffi::CoglMaterialLayer,
152 ) -> glib::translate::Borrowed<MaterialLayer> {
153 glib::translate::Borrowed::new(MaterialLayer(ptr))
154 }
155}
156
157#[doc(hidden)]
158impl FromGlibPtrBorrow<*mut ffi::CoglMaterialLayer> for MaterialLayer {
159 unsafe fn from_glib_borrow(
160 ptr: *mut ffi::CoglMaterialLayer,
161 ) -> glib::translate::Borrowed<Self> {
162 glib::translate::Borrowed::new(*(ptr as *mut MaterialLayer))
163 }
164}
165
166#[doc(hidden)]
167impl FromGlibPtrBorrow<*const ffi::CoglMaterialLayer> for MaterialLayer {
168 unsafe fn from_glib_borrow(
169 ptr: *const ffi::CoglMaterialLayer,
170 ) -> glib::translate::Borrowed<Self> {
171 glib::translate::Borrowed::new(*(ptr as *const MaterialLayer))
172 }
173}
174
175impl FromGlibPtrFull<ffi::CoglMaterialLayer> for MaterialLayer {
176 #[inline]
177 unsafe fn from_glib_full(_: ffi::CoglMaterialLayer) -> MaterialLayer {
178 unimplemented!()
179 }
180}
181
182impl FromGlibContainerAsVec<ffi::CoglMaterialLayer, *mut ffi::CoglMaterialLayer> for MaterialLayer {
183 unsafe fn from_glib_none_num_as_vec(ptr: *mut ffi::CoglMaterialLayer, num: usize) -> Vec<Self> {
184 if num == 0 || ptr.is_null() {
185 return Vec::new();
186 }
187
188 let mut res = Vec::with_capacity(num);
189 for i in 0..num {
190 res.push(from_glib_none(ptr::read(ptr.add(i))));
191 }
192 res
193 }
194
195 unsafe fn from_glib_container_num_as_vec(
196 ptr: *mut ffi::CoglMaterialLayer,
197 num: usize,
198 ) -> Vec<Self> {
199 let res = FromGlibContainerAsVec::from_glib_none_num_as_vec(ptr, num);
200 glib_sys::g_free(ptr as *mut _);
201 res
202 }
203
204 unsafe fn from_glib_full_num_as_vec(ptr: *mut ffi::CoglMaterialLayer, num: usize) -> Vec<Self> {
205 if num == 0 || ptr.is_null() {
206 return Vec::new();
207 }
208
209 let mut res = Vec::with_capacity(num);
210 for i in 0..num {
211 res.push(from_glib_full(ptr::read(ptr.add(i))));
212 }
213 glib_sys::g_free(ptr as *mut _);
214 res
215 }
216}
217
218impl FromGlibPtrArrayContainerAsVec<ffi::CoglMaterialLayer, *mut ffi::CoglMaterialLayer>
219 for MaterialLayer
220{
221 unsafe fn from_glib_none_as_vec(ptr: *mut ffi::CoglMaterialLayer) -> Vec<Self> {
222 FromGlibContainerAsVec::from_glib_none_num_as_vec(ptr, c_ptr_array_len(ptr))
223 }
224
225 unsafe fn from_glib_container_as_vec(ptr: *mut ffi::CoglMaterialLayer) -> Vec<Self> {
226 FromGlibContainerAsVec::from_glib_container_num_as_vec(ptr, c_ptr_array_len(ptr))
227 }
228
229 unsafe fn from_glib_full_as_vec(ptr: *mut ffi::CoglMaterialLayer) -> Vec<Self> {
230 FromGlibContainerAsVec::from_glib_full_num_as_vec(ptr, c_ptr_array_len(ptr))
231 }
232}