-
Notifications
You must be signed in to change notification settings - Fork 89
Labels
⬆️ featureNew feature or requestNew feature or request👷 refactorSomething needs to changeSomething needs to change🥳🎉 1.0This issue is part of stabilization for 1.0 releaseThis issue is part of stabilization for 1.0 release
Description
We could move some of our "magic" methods into traits, which would make it a lot more obvious where they are coming from, and would allow us to e.g. "inherit" methods from QObject, reason about types, etc.
// cxx-qt crate - may also need to go in cxx-qt-lib
mod ffi {
extern "C++" {
type QObject;
fn children(self: &QObject) -> QList<*mut QObject>;
fn objectName(self: &QObject) -> QString;
}
}
// Note: QtObject vs QObject
trait QtObject {
fn as_qobject(&self) -> &cxx_qt_lib::QObject;
fn as_qobject_mut(&mut self) -> Pin<&mut cxx_qt_lib::QObject>;
fn children(&self) -> QList<*mut QObject> {
as_qobject().children()
}
fn objectName(&self) -> Pin<&mut cxx_qt_lib::QObject> {
as_qobject().objectName()
}
// ... other methods wrapped as needed.
}
trait CxxQtType {
type Inner;
fn rust(&self) -> &Self::Inner;
fn rust_mut(self: Pin<&mut self>) -> &mut Self::Inner;
}
Then in C++, we could generate a generic cast to QObject, similar to how we do constructors.
template<typename T>
QObject *as_qobject(T* t) {
return static_cast<QObject*>(t);
}
Metadata
Metadata
Assignees
Labels
⬆️ featureNew feature or requestNew feature or request👷 refactorSomething needs to changeSomething needs to change🥳🎉 1.0This issue is part of stabilization for 1.0 releaseThis issue is part of stabilization for 1.0 release
Type
Projects
Status
Done