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