Open felinira opened 7 months ago
Also the instance struct
The goal here would be the following, and making it actually compile, which requires adding bounds and derive Clone+Copy
impls in various places
diff --git a/glib/src/subclass/types.rs b/glib/src/subclass/types.rs
index d4547986ce4..18697626d8f 100644
--- a/glib/src/subclass/types.rs
+++ b/glib/src/subclass/types.rs
@@ -47,7 +47,10 @@ struct PrivateStruct<T: ObjectSubclass> {
/// required in the instance struct.
///
/// [`basic::InstanceStruct`]: ../basic/struct.InstanceStruct.html
-pub unsafe trait InstanceStruct: Sized + 'static {
+pub unsafe trait InstanceStruct: Sized + 'static
+where
+ Self: Copy,
+{
// rustdoc-stripper-ignore-next
/// Corresponding object subclass type for this instance struct.
type Type: ObjectSubclass;
@@ -175,7 +178,10 @@ impl<T: ObjectSubclassIs<Subclass = S>, S: ObjectSubclass<Type = Self>> ObjectSu
/// required in the class struct, e.g. for declaring new virtual methods.
///
/// [`basic::ClassStruct`]: ../basic/struct.ClassStruct.html
-pub unsafe trait ClassStruct: Sized + 'static {
+pub unsafe trait ClassStruct: Sized + 'static
+where
+ Self: Copy,
+{
// rustdoc-stripper-ignore-next
/// Corresponding object subclass type for this class struct.
type Type: ObjectSubclass;
We should also consider not copying the interface struct ourselves here but simply taking the pointer of it that is already stored inside GObject. g_type_class_peek_parent()
or so should be able to get us that.
Class structs should have a bound on
Copy
, because that's what GObject is doing internally. If we were exposingbase_init
this could be avoided.See https://github.com/gtk-rs/gtk-rs-core/pull/1378#discussion_r1585972731_