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 interface bounds to Impls #1883

Merged
merged 2 commits into from
Oct 25, 2024

Conversation

felinira
Copy link
Contributor

What this does

  • Require everyone to specify the @implements directive for all interfaces that are implemented by the object, even interfaces implemented by the parent. (positive check)

What this doesn't do

  • Check whether the interface is actually implemented (negative check), you can still write whatever in the wrapper macro and nothing checks this. This is a hard problem, and if at all only solveable at runtime. (not sure how, but it could be possible by doing some assertions on type_init maybe, needs more research)
  • I think the error messages could be better, which would be possible by adding #[diagnostic::on_unimplemented] for the IsA trait (it is stable since 1.78).

See also gtk-rs/gtk-rs-core#1551

gtk4/src/subclass/mod.rs Outdated Show resolved Hide resolved
PrintOperationPreviewImpl + ObjectSubclass<Type: IsA<PrintOperation>>
ObjectImpl + ObjectSubclass<Type: IsA<PrintOperation> + IsA<PrintOperationPreview>>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with other implementations. This derives from glib::Object, but implements gtk::PrintOperationPreview

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does a print operation necessarily requires a print operation preview?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes https://docs.gtk.org/gtk4/class.PrintOperation.html

It is surprising to me as well that it's set up that way, but it is how it is.

class Gtk.PrintOperation : GObject.Object
  implements Gtk.PrintOperationPreview {
  /* No available fields */
}

examples/confetti_snapshot_animation/main.rs Outdated Show resolved Hide resolved
gtk4/src/subclass/mod.rs Outdated Show resolved Hide resolved
gtk4/src/subclass/mod.rs Outdated Show resolved Hide resolved
@felinira felinira force-pushed the wip/interface-bounds branch 3 times, most recently from 8d2bf10 to f47c400 Compare October 23, 2024 13:56
@felinira
Copy link
Contributor Author

forgot doc tests, they should hopefully pass now

Copy link
Member

@bilelmoussaoui bilelmoussaoui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise lgtm

@felinira felinira force-pushed the wip/interface-bounds branch 5 times, most recently from 74a9395 to 78011d6 Compare October 24, 2024 21:24
@bilelmoussaoui
Copy link
Member

Almost there!

@felinira felinira force-pushed the wip/interface-bounds branch 2 times, most recently from 328464d to 918adf9 Compare October 24, 2024 21:53
@felinira
Copy link
Contributor Author

Almost there!

CI driven development! 🙄

I could have spent this time to make a toolbox with gtk nightly so that I can use --all-features locally, but alas I spent it fighting CI instead.

@bilelmoussaoui bilelmoussaoui merged commit 453237c into gtk-rs:main Oct 25, 2024
40 checks passed
@bilelmoussaoui
Copy link
Member

Actually, you don't even need that. There is a trick, to build by passing the same rustc flags we pass for the docs. It won't try to link against gtk ;) I forgot the details though, can find that again if you ever need it

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.

2 participants