-
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
Explore how to represent container types #347
Comments
For maps do we group the key and value together to created a combined type/struct ? Then have to implement the trait for every combination you want. This would be similar to QHash internally that has Then a developer could define |
Can we copy how Eg
or
The remaining question if we went with that route would be, where does the generated C++ end up? In the cpp file for the bridge module? |
We should also consider if can upstream |
Maybe the API would actually be |
These might already exist in CXX see https://github.com/dtolnay/cxx/blob/c7060d40361c4d955fc64adf35f67b28b5c75299/tests/ui/vector_autotraits.rs |
Also define all primitive types and cxx_qt_lib types as T. Related to KDAB#347
Also define all primitive types and cxx_qt_lib types as T. Related to KDAB#347
For the initial code we will requires developers to implement the trait themselves on the custom type for container types. Later we can look again at an impl generator #355 |
Also define all primitive types and cxx_qt_lib types as T. Related to KDAB#347
Also define all primitive types and cxx_qt_lib types as T. Related to KDAB#347
Also define all primitive types and cxx_qt_lib types as T. Related to KDAB#347
Also define all primitive types and cxx_qt_lib types as T. Related to KDAB#347
Also define all primitive types and cxx_qt_lib types as T. Related to KDAB#347
Also define all primitive types and cxx_qt_lib types as T. Related to KDAB#347
Also define all primitive types and cxx_qt_lib types as T. Related to KDAB#347
Also define all primitive types and cxx_qt_lib types as T. Related to KDAB#347
For Qt5 vs Qt6 fun for QVector and QList, do we actually just implement both QVector and QList as types their have their internal size etc be different depending on Qt version, as the API that we'll expose to Rust looks similar even with the changes? |
All container types are done :-D |
Also define all primitive types and cxx_qt_lib types as T. Related to KDAB#347
QtCore
QLinkedList ? (Qt5 only?)Problems
Container types are hard to represent via extern FFI or CXX blocks due to the following problems
T::push_back
CXX
For representing
std::vector<T>
, CXX has aCxxVector<T>
this has PhantomData inside it https://github.dev/dtolnay/cxx/blob/c7060d40361c4d955fc64adf35f67b28b5c75299/src/cxx_vector.rs#L24Then a trait
VectorElement
https://github.dev/dtolnay/cxx/blob/c7060d40361c4d955fc64adf35f67b28b5c75299/src/cxx_vector.rs#L333 is implemented for all supported typesT
. In methods such aslen
thenT::__vector_size(self)
is used. https://github.dev/dtolnay/cxx/blob/c7060d40361c4d955fc64adf35f67b28b5c75299/src/cxx_vector.rs#L45A macro is used to generate the trait implementation for each type which then, eg for
__vector_size
, uses an inlineextern "C"
block to create a method such ascxxbridge1$std$vector$i32$size
which then has the type__vector_size(&CxxVector<i32>) -> usize;
https://github.dev/dtolnay/cxx/blob/c7060d40361c4d955fc64adf35f67b28b5c75299/src/cxx_vector.rs#L401There is then also C++ generation in the write phase which creates the matching C++ method with the name and type then using
return self.size();
https://github.dev/dtolnay/cxx/blob/c7060d40361c4d955fc64adf35f67b28b5c75299/gen/src/write.rs#L1886Questions
This allows you to represent something with a single type in Rust, but has the following problems
T::__map_size(self)
work, as it needs to have both K and V ?VectorElement
is undocumented, so it's not documented that developers could implement this on their own types, we should have a stable trait for thisVectorElement
impl to link to (unless we can generate this somehow?)CXX-Qt
For
QSet
,QVector
, Qt5List` we can likely do something similar to CXX, but with a documented element trait.For
QHash
,QMap
we need to figure out a further solution.The text was updated successfully, but these errors were encountered: