-
Notifications
You must be signed in to change notification settings - Fork 77
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
Traits for CxxQtType/QtObject #562
Comments
I also wonder with this if we have an existing C++ QObject if we should allow for tagging it to get the trait implemented on it ? Eg if we have unsafe extern "C++Qt" {
type MyQObject;
} This won't have the Eg unsafe extern "C++Qt" {
#[qobject]
type MyQObject;
} |
Hm, shouldn't all classes in Though that brings up the question of whether all types within C++Qt are actually QObjects 🤔 But maybe we should start requiring |
Also another suggestion regarding naming, we could use |
But I fear it's a slight inconsistency with Maybe the
|
Note: We should potentially make use of Once https://doc.rust-lang.org/std/pin/struct.Pin.html#method.as_deref_mut is no longer nightly only, we could even use Something along the lines of: unsafe trait Inherits {
// note using an associated type only allows for single-inheritance!
type Base;
fn upcast_ptr(self: *mut Self) -> *mut Base;
fn upcast_mut(self: Pin<&mut Self>) -> Pin<&mut Base> {
// provided by the trait
}
fn upcast<'a>(&'a self) -> &'a Base { }
}
// unsure whether this is possible, but would be awesome!
impl<T> Deref for T where T: Inherits {
type Target = <T as Inherits>::Base;
...
} |
It would be nice if we could use |
Right, I was hoping we could even get away without explicit |
Rust is verbose and is one of its strong points. Automatic casting has caused problems for me in the past, which is why I would be against it. In my opinion, Rust's type inference powered |
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.
Then in C++, we could generate a generic cast to QObject, similar to how we do constructors.
The text was updated successfully, but these errors were encountered: