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 [`TypeInfo`][crate::TypeInfo] structure in the
11/// [`TypePluginExtManual::complete_type_info()`][crate::prelude::TypePluginExtManual::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#[derive(Debug, Copy, Clone)]
15#[doc(alias = "GTypeInfo")]
16#[repr(transparent)]
17pub struct TypeInfo(pub(crate) gobject_ffi::GTypeInfo);
18
19impl TypeInfo {
20 // rustdoc-stripper-ignore-next
21 /// Returns a `GTypeInfo` pointer.
22 #[doc(hidden)]
23 #[inline]
24 pub fn as_ptr(&self) -> *mut gobject_ffi::GTypeInfo {
25 &self.0 as *const gobject_ffi::GTypeInfo as *mut _
26 }
27
28 // rustdoc-stripper-ignore-next
29 /// Borrows the underlying C value mutably.
30 #[doc(hidden)]
31 #[inline]
32 pub unsafe fn from_glib_ptr_borrow_mut<'a>(ptr: *mut gobject_ffi::GTypeInfo) -> &'a mut Self {
33 &mut *(ptr as *mut Self)
34 }
35}
36
37impl Default for TypeInfo {
38 // rustdoc-stripper-ignore-next
39 /// Creates a new TypeInfo with default value.
40 fn default() -> Self {
41 Self(gobject_ffi::GTypeInfo {
42 class_size: 0u16,
43 base_init: None,
44 base_finalize: None,
45 class_init: None,
46 class_finalize: None,
47 class_data: ::std::ptr::null(),
48 instance_size: 0,
49 n_preallocs: 0,
50 instance_init: None,
51 value_table: ::std::ptr::null(),
52 })
53 }
54}