Skip to content

WIP add book entry for instantiating in Rust #1229

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 1 commit into
base: main
Choose a base branch
from

Conversation

BenFordTytherington
Copy link
Collaborator

No description provided.

@BenFordTytherington BenFordTytherington force-pushed the document-rust-initialisation branch 2 times, most recently from 8323dcd to 701404f Compare March 14, 2025 15:37
Copy link

codecov bot commented Mar 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

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

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1229   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           73        73           
  Lines        12612     12612           
=========================================
  Hits         12612     12612           

☔ 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 document-rust-initialisation branch 6 times, most recently from 064933a to b81db2f Compare March 14, 2025 16:42
@BenFordTytherington BenFordTytherington marked this pull request as ready for review March 14, 2025 17:01
@LeonMatthesKDAB
Copy link
Collaborator

@BenFordTytherington Please also document that you can add constructor arguments if required :)

@BenFordTytherington
Copy link
Collaborator Author

@BenFordTytherington Please also document that you can add constructor arguments if required :)

I wasn't aware that was an option with these templates, what would that syntax look like?

@BenFordTytherington BenFordTytherington force-pushed the document-rust-initialisation branch from b81db2f to 16ec690 Compare March 28, 2025 16:41
@LeonMatthesKDAB
Copy link
Collaborator

@BenFordTytherington , it follows the same pattern as our construct function, e.g. here:

fn construct(_: &QVector_i64) -> QVector_i64;

You just declare the appropriate parameters and if the declared parameters match an existing constructor it will just work :)
And you can even create multiple constructors that way by renaming them.

Most QObjects for example can be created with an optional QObject* parent, so that could be a good example to show, e.g.:

#[namespace = "rust::cxxqtlib1"]
unsafe extern "C++" {
    include!("cxx-qt-lib/common.h");

    #[rust_name = "my_object_new"]
    fn make_unique() -> UniquePtr<MyObject>;
    
    #[rust_name = "my_object_new_with_parent"]
    fn make_unique(parent: *mut QObject) -> UniquePtr<MyObject>;
}

I think the docs should also mention that these functions are provided by CXX-Qt-lib as helper functions (which explains why they are in the rust::cxxqtlib1 namespace.
It's important to note that this is not std::make_unique.
These wrappers are specifically designed for better CXX compatibility.

@BenFordTytherington BenFordTytherington force-pushed the document-rust-initialisation branch 2 times, most recently from c7ad9d6 to e39c5b1 Compare April 7, 2025 16:33
@BenFordTytherington BenFordTytherington force-pushed the document-rust-initialisation branch from e39c5b1 to e4ab2f6 Compare April 8, 2025 08:33
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