Skip to content

Add shorthand for &self in RustQt blocks where the type can be inferred #1249

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

BenFordTytherington
Copy link
Collaborator

Allows Pin<&mut Self> and &self inside the bridge, as shorthand.

Copy link

codecov bot commented Apr 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (64d4ee6) to head (698c4d7).

Additional details and impacted files
@@            Coverage Diff             @@
##              main     #1249    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           73        74     +1     
  Lines        12612     12757   +145     
==========================================
+ Hits         12612     12757   +145     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@BenFordTytherington BenFordTytherington force-pushed the add-self-shorthand branch 3 times, most recently from a5f04f7 to 32371fd Compare April 4, 2025 15:32
…here the type can be inferred

- If exactly one QObject is present in a block with a method, it will infer `Self` to represent that qobject
- Updates one of the examples to test this out
@BenFordTytherington BenFordTytherington marked this pull request as ready for review April 4, 2025 15:54
@BenFordTytherington
Copy link
Collaborator Author

Tried to implement in the qml_features example and there is a cxx error about there being multiple types in the block, even though there is only one qobject in the example, which may be because it adds the QObject import?

- QObjects, and invokables are now 2D Vecs, kept in their original block
- Adds some helper methods for iterating like they are still flat
- Add function call to cxx-qt-build and cxx-qt-macro
- Inlining now happens after parsing and before structuring
Comment on lines +49 to +53
for block in 0..data.qobjects.len() {
let methods = &mut data.methods[block];
let signals = &mut data.signals[block];
let inherited = &mut data.inherited_methods[block];
let qobjects = &data.qobjects[block];
Copy link
Collaborator

Choose a reason for hiding this comment

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

almost seems like you could use zip here but seems it'd need to be a nested as it only supports combining two iterators? :-/

it'd probably end up as like

for (((qobject, method), signal), inherit_method) in zip(zip(zip(data.qobjects, data.methods), data.signals), data.inherited_methods)

But then does that end up being less readable 🤣

let inherited = &mut data.inherited_methods[block];
let qobjects = &data.qobjects[block];

let inline_self = qobjects.len() == 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we only ever need to care about QObjects? eg do we support non-qobject attributed types in extern C++Qt / RustQt blocks ?

and do we need to support normal type items in C++/Rust blocks if we start avoiding passthrough, this would be a separate change though?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

At the minute we don't support any types in C++Qt blocks that don't have a #[qobject] attribute, and I wasn't sure about RustQt blocks, but yeah this may a consideration, that it can be any type defs, not just QObjects, i guess to inline free functions.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Right it's fine for now, but might need to change later depending what we do

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.

Support for shortand &self in bridge
2 participants