-
Notifications
You must be signed in to change notification settings - Fork 92
Description
I feel the need for contributing guidelines and code style. Code style should cover both formatting rules (and tools used for automation) and general patterns for hand-written bindings.
For example, I like how it is done in in winapi crate: https://github.com/retep998/winapi-rs/blob/0.3/CONTRIBUTING.md
Things to consider, based on the articles about previous attempts to generate C++ bindings for rust:
-
Method overload renaming rules
For example, in Qt documentation they are differentiated by suffix number rather than by signature.
-
Constructor overloads:
- single-argument constructors are expressed using
Fromtrait. - multiple-argument constructors wrapped in dedicated factory function with some sensible name like
impl AB { fn from_a_b(a: A, b: B) -> Self {...} }— what is the naming pattern for them?
- single-argument constructors are expressed using
-
Method overloads:
- In Rust, method overloading trait-based.
It works best on single-argument overloads, while multiple arguments may be stacked in tuple.
For example, see ToSocketAddrs.
- In Rust, method overloading trait-based.
-
-
Operators overload
Probably, the easiest part, since in Rust they are generic and single-argumented. -
Default arguments
In C++ omitted default arguments are substituted at compile time with what was defined in header file. It can be mapped toOptions in Rust. Then, for eachNoneargument, a separatecpp!macro invocation would need to be done to retrieve the corresponding default value. Finally, call C++ function with all arguments supplied. -
C-style
enums with multiple variants mapping to same values. Sounds like the right job for abitflags-style macro.
Or just don't use enum at all — that's what winapi is doing: every define becomes just a const.
Then again, it may be a place for two-layered system, with low-level raw bindings and high-level rusty ones. -
Short-circuiting on Rust side
This one is about re-implementing basic things like QRect in native Rust rather than calling into Qt.- Is it acceptable?
- If so, what are the rules?
-
Imitating inheritance?
-
Feature-flagging classes and methods added in Qt x.y
- Chain features such that e.g. qt_5_12 enables qt_5_11 and so on.
Even though current 5.15 is the last in Qt5 branch, feature-flagging still would apply in Qt6.
- Chain features such that e.g. qt_5_12 enables qt_5_11 and so on.
-
Licensing and copyright management rules
What else?