Skip to content

Shorthand to directly wrap functions on the inner Rust struct #1235

Open
@LeonMatthesKDAB

Description

@LeonMatthesKDAB

Currently, if you want to expose a function on the inner Rust struct to C++/QML, you always have to write a wrapper function outside the bridge.

E.g.:

#[cxx_qt::bridge]
mod qobject {
extern "RustQt" {

#[qobject]
type MyObject = super::MyObjectRust;

fn my_fun(self: &MyObject) -> i32;

}
}

impl qobject::MyObject {
    fn my_fun(&self) -> i32 {
        self.rust().my_fun();
    }
}

We could consider automating this if you provide a given attribute to the declaration (e.g. #[inner]).

Example:

#[cxx_qt::bridge]
mod qobject {
extern "RustQt" {

#[qobject]
type MyObject = super::MyObjectRust;

#[inner] // auto-generates the wrapper outside the bridge
fn my_fun(self: &MyObject) -> i32;

}
}

Note that this may cause issues with Result<>, as the Error type wouldn't necessarily be known.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions