| 1 | // Take a look at the license at the top of the repository in the LICENSE file. |
| 2 | |
| 3 | // rustdoc-stripper-ignore-next |
| 4 | //! This module contains basic instance and class structs to be used for |
| 5 | //! `GObject` subclasses that don't require any additional data in these |
| 6 | //! structs and don't provide any new virtual methods. |
| 7 | |
| 8 | use std::{fmt, ops}; |
| 9 | |
| 10 | use super::prelude::*; |
| 11 | use crate::prelude::*; |
| 12 | |
| 13 | // rustdoc-stripper-ignore-next |
| 14 | /// A basic instance struct that does not store any additional data. |
| 15 | #[repr (C)] |
| 16 | pub struct InstanceStruct<T: ObjectSubclass> { |
| 17 | parent: <T::ParentType as ObjectType>::GlibType, |
| 18 | } |
| 19 | |
| 20 | impl<T: ObjectSubclass> fmt::Debug for InstanceStruct<T> |
| 21 | where |
| 22 | <T::ParentType as ObjectType>::GlibType: fmt::Debug, |
| 23 | { |
| 24 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 25 | f&mut DebugStruct<'_, '_>.debug_struct("InstanceStruct" ) |
| 26 | .field(name:"parent" , &self.parent) |
| 27 | .finish() |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | unsafe impl<T: ObjectSubclass> super::types::InstanceStruct for InstanceStruct<T> { |
| 32 | type Type = T; |
| 33 | } |
| 34 | |
| 35 | // rustdoc-stripper-ignore-next |
| 36 | /// A basic class struct that does not store any additional data |
| 37 | /// or virtual methods. |
| 38 | #[repr (C)] |
| 39 | pub struct ClassStruct<T: ObjectSubclass> { |
| 40 | parent_class: <T::ParentType as ObjectType>::GlibClassType, |
| 41 | } |
| 42 | |
| 43 | impl<T: ObjectSubclass> fmt::Debug for ClassStruct<T> |
| 44 | where |
| 45 | <T::ParentType as ObjectType>::GlibClassType: fmt::Debug, |
| 46 | { |
| 47 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 48 | f&mut DebugStruct<'_, '_>.debug_struct("InstanceStruct" ) |
| 49 | .field(name:"parent_class" , &self.parent_class) |
| 50 | .finish() |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | unsafe impl<T: ObjectSubclass> super::types::ClassStruct for ClassStruct<T> { |
| 55 | type Type = T; |
| 56 | } |
| 57 | |
| 58 | impl<T: ObjectSubclass> ops::Deref for ClassStruct<T> { |
| 59 | type Target = crate::Class<<T as ObjectSubclass>::Type>; |
| 60 | |
| 61 | #[inline ] |
| 62 | fn deref(&self) -> &Self::Target { |
| 63 | unsafe { &*(self as *const _ as *const Self::Target) } |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | impl<T: ObjectSubclass> ops::DerefMut for ClassStruct<T> { |
| 68 | #[inline ] |
| 69 | fn deref_mut(&mut self) -> &mut Self::Target { |
| 70 | unsafe { &mut *(self as *mut _ as *mut Self::Target) } |
| 71 | } |
| 72 | } |
| 73 | |