Skip to content

Conversation

BenFordTytherington
Copy link
Collaborator

@BenFordTytherington BenFordTytherington commented May 20, 2025

Closes #1235

Adds the auto_wrap attribute which will generate the wrapper function for methods defined in the bridge.

Copy link

codecov bot commented May 20, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (8a87203) to head (b30fe57).

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1278   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           75        75           
  Lines        12784     12846   +62     
=========================================
+ Hits         12784     12846   +62     

☔ 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.

@@ -43,3 +43,8 @@ For [`#[qproperty]`](./extern_rustqt.md#properties), a CXX or Rust name can be p
The `#[auto_cxx_name]` and `#[auto_rust_name]` attributes can be used to automatically rename cxx and rust names.
These are placed at a block level on `extern "RustQt"` or `extern "C++Qt"` blocks, and will automatically case convert the items inside, unless they specify either a `rust_name` or `cxx_name`.
By default `#[auto_cxx_name]` will generate a camelCase conversion for`cxx_name` and `#[auto_rust_name]` will generate a snake_case conversion for `rust_name`.

### Automatic wrapping
Copy link
Collaborator

Choose a reason for hiding this comment

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

an example that is compiled would be good too. I think the load_color here could be changed to use it https://github.com/KDAB/cxx-qt/blob/main/examples/qml_features/rust/src/invokables.rs#L99

So that you have load_color auto_wrapped to read the inner as_qcolor on the Rust type (which could be renamed)

@BenFordTytherington BenFordTytherington force-pushed the wrapper-shorthand branch 2 times, most recently from bf40f52 to b30fe57 Compare September 17, 2025 15:31
#unsafe_call fn #invokable_ident_rust(#parameter_signatures) #return_type;
}
impl #qualified_impl {
#method_safety fn #invokable_ident_rust(#parameter_signatures) #return_type {
Copy link
Collaborator

Choose a reason for hiding this comment

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

think you need to consider the visibility here too? eg pass through the pub or pub(super) etc

}
impl #qualified_impl {
pub #method_safety fn #invokable_ident_rust(#parameter_signatures) #return_type {
self.#inner_fn.#invokable_ident_rust(#call_parameters)
Copy link
Collaborator

Choose a reason for hiding this comment

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

looking at other generators they have use cxx_qt::CxxQtType; within the function so that they can reach the trait implementation of rust() / rust_mut(). Wonder if we need the same here?

eg here https://github.com/KDAB/cxx-qt/blob/main/crates/cxx-qt-gen/src/generator/rust/property/setter.rs#L71

@@ -780,6 +780,11 @@ cxx_qt::static_assertions::assert_eq_size!(
cxx_qt::signalhandler::CxxQtSignalHandler<SecondObjectCxxQtSignalClosurepropertyNameChanged>,
[usize; 2]
);
impl ffi::SecondObject {
fn my_function(self: &SecondObject, param: i32) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

aha this type should be ffi::SecondObject that's why it's failing :-)

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.

Shorthand to directly wrap functions on the inner Rust struct
2 participants