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

Add additional type bounds to Impl traits #1854

Merged
merged 2 commits into from
Oct 18, 2024

Conversation

felinira
Copy link
Contributor

@felinira felinira commented Oct 3, 2024

Mirrors gtk-rs/gtk-rs-core#1519
See gtk-rs/gtk-rs-core#1515

Open questions:

  • GInitiallyUnowned: Technically a parent class, but we mostly ignore it in other places already
  • Interfaces, especially the ones implemented by GtkWidget are currently not covered by the implementing classes. Should they? One normally doesn't need to reimplement them, but we need to check whether we are required to specify them for safety reasons anyway

gtk4/src/subclass/accessible_range.rs Outdated Show resolved Hide resolved
gtk4/src/subclass/orientable.rs Outdated Show resolved Hide resolved
@sdroege
Copy link
Member

sdroege commented Oct 4, 2024

* [ ]  `GInitiallyUnowned`: Technically a parent class, but we mostly ignore it in other places already

I would ignore it here. It doesn't have its own impl trait, its own API, or anything. It's just a strange marker class :)

* [ ]  Interfaces, especially the ones implemented by `GtkWidget` are currently not covered by the implementing classes. Should they? One normally doesn't need to reimplement them, but we need to check whether we are required to specify them for safety reasons anyway

What do you mean, can you give a concrete example?

@felinira
Copy link
Contributor Author

felinira commented Oct 5, 2024

What do you mean, can you give a concrete example?

Right now we don't ensure that people add @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget for their widget subclasses.

We will now start requiring everyone to start adding all their parent classes here via @extends. But should we also require those interfaces to be specified as well? As in, add additional constraints to WidgetImpl to include IsA<Accessible>, IsA<Buildable> and IsA<ConstraintTarget>.

Or is this superfluous? I can see this being advantageous in the sense that the wrapper macro always forces you to add all required interfaces, and just following compiler errors will lead to a correct and exhaustive implementation. However it would also add additional burden, as you'd need to specify those three bounds everywhere even though Widget should basically imply them.

@bilelmoussaoui
Copy link
Member

We will now start requiring everyone to start adding all their parent classes here via @extends. But should we also require those interfaces to be specified as well? As in, add additional constraints to WidgetImpl to include IsA, IsA and IsA.

I think that is the conceptually correct thing to do but it will make every app developer's life more miserable given our poor subclassing code infrastructure.

On the other hand, enforcing things to be correctly handled would mean an easier path forward for some more automation using macros.

So for my side, I will just take the risk and do that. Could you give it a try in a separate commit to see the impact?

@sdroege
Copy link
Member

sdroege commented Oct 14, 2024

I think requiring this is more correct and we should enforce it.

@sdroege
Copy link
Member

sdroege commented Oct 14, 2024

@felinira This also requires some additional change in gtk-rs-core or not? If so, we can also do it in a separate PR if you prefer

@bilelmoussaoui
Copy link
Member

@felinira This also requires some additional change in gtk-rs-core or not? If so, we can also do it in a separate PR if you prefer

This cannot affect gtk-rs-core, there is no base object that implements some interfaces and have various sub-types. Maybe gstreamer-rs though :)

@sdroege
Copy link
Member

sdroege commented Oct 14, 2024

Ah I thought one of the GIO interfaces maybe :)

@felinira felinira closed this Oct 15, 2024
@felinira felinira reopened this Oct 15, 2024
@felinira
Copy link
Contributor Author

Could you give it a try in a separate commit to see the impact?

Sure, will do that later this week

@sdroege
Copy link
Member

sdroege commented Oct 18, 2024

Let's get this in then and do the interfaces separately or what do you think?

@bilelmoussaoui
Copy link
Member

Sure

@bilelmoussaoui bilelmoussaoui merged commit a65c21f into gtk-rs:master Oct 18, 2024
80 checks passed
@bilelmoussaoui
Copy link
Member

Thanks @felinira

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

Successfully merging this pull request may close these issues.

3 participants