Skip to content

Contributing guidelines, code style #81

@ratijas

Description

@ratijas

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 From trait.
      • 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?
    • 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.
  • 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 to Options in Rust. Then, for each None argument, a separate cpp! 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 a bitflags-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.
  • Licensing and copyright management rules

What else?

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-discussionCategory: Discussion or questions that doesn't represent real issues.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions