Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class structs should be Copy #1381

Open
felinira opened this issue May 3, 2024 · 3 comments
Open

Class structs should be Copy #1381

felinira opened this issue May 3, 2024 · 3 comments

Comments

@felinira
Copy link
Contributor

felinira commented May 3, 2024

Class structs should have a bound on Copy, because that's what GObject is doing internally. If we were exposing base_init this could be avoided.

See #1378 (comment)_

@sdroege
Copy link
Member

sdroege commented May 3, 2024

Also the instance struct

@sdroege
Copy link
Member

sdroege commented May 8, 2024

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;

@sdroege
Copy link
Member

sdroege commented May 11, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants