glib/gobject/type_info.rs
1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use crate::gobject_ffi;
4
5/// This structure is used to provide the type system with the information
6/// required to initialize and destruct (finalize) a type's class and
7/// its instances.
8///
9/// The initialized structure is passed to the g_type_register_static() function
10/// (or is copied into the provided #GTypeInfo structure in the
11/// g_type_plugin_complete_type_info()). The type system will perform a deep
12/// copy of this structure, so its memory does not need to be persistent
13/// across invocation of g_type_register_static().
14// rustdoc-stripper-ignore-next-stop
15/// This structure is used to provide the type system with the information
16/// required to initialize and destruct (finalize) a type's class and
17/// its instances.
18///
19/// The initialized structure is passed to the g_type_register_static() function
20/// (or is copied into the provided #GTypeInfo structure in the
21/// g_type_plugin_complete_type_info()). The type system will perform a deep
22/// copy of this structure, so its memory does not need to be persistent
23/// across invocation of g_type_register_static().
24#[derive(Debug, Copy, Clone)]
25#[doc(alias = "GTypeInfo")]
26#[repr(transparent)]
27pub struct TypeInfo(pub(crate) gobject_ffi::GTypeInfo);
28
29impl TypeInfo {
30 // rustdoc-stripper-ignore-next
31 /// Returns a `GTypeInfo` pointer.
32 #[doc(hidden)]
33 #[inline]
34 pub fn as_ptr(&self) -> *mut gobject_ffi::GTypeInfo {
35 &self.0 as *const gobject_ffi::GTypeInfo as *mut _
36 }
37
38 // rustdoc-stripper-ignore-next
39 /// Borrows the underlying C value mutably.
40 #[doc(hidden)]
41 #[inline]
42 pub unsafe fn from_glib_ptr_borrow_mut<'a>(ptr: *mut gobject_ffi::GTypeInfo) -> &'a mut Self {
43 unsafe { &mut *(ptr as *mut Self) }
44 }
45}
46
47impl Default for TypeInfo {
48 // rustdoc-stripper-ignore-next
49 /// Creates a new TypeInfo with default value.
50 fn default() -> Self {
51 Self(gobject_ffi::GTypeInfo {
52 class_size: 0u16,
53 base_init: None,
54 base_finalize: None,
55 class_init: None,
56 class_finalize: None,
57 class_data: ::std::ptr::null(),
58 instance_size: 0,
59 n_preallocs: 0,
60 instance_init: None,
61 value_table: ::std::ptr::null(),
62 })
63 }
64}