Bindings for operators and special member functions

Here we describe how Crubit bindings work with C++ special member functions and operator overloading (e.g. the copy constructor, or operator==) and with traits from the Rust standard library (e.g. the Clone or PartialEq traits).

Rust traits which return Self by value (or use mutable references) are only implemented in the bindings for a given C++ type if that type is is Unpin.

Bidirectional map

The following special member functions and traits are mapped bidirectionally:

C++RustNotes
Default constructorDefaultC++ types must be Unpin

One-way map of C++ special member functions into Rust traits

If the C++ type is Unpin, then the C++ special member functions below are mapped one-way into the corresponding Rust traits as follows:

C++ APIRust bindingsNotes
Trivial copy constructorCopyAlso requires that the C++ type
: : : is non-abstract and has a :
: : : public, trivial copy constructor :
: : : and destructor. :
: : :
TODO(b/258249993): Provide :
: : : bidirectional map. :
Custom copy constructorCloneTODO(b/259741191): Provide
: : : bidirectional map. :
DestructorDropTODO(b/258251148): Provide
: : : bidirectional map. :
Constructor taking singleFrom<T>Regardless if the constructor is
: parameter of type T : : explicit in the C++ API or not :

The C++ binary operators below are mapped one-way into the corresponding Rust traits as follows:

C++ APIRust bindings
operator==PartialEq
operator<PartialOrd
operator+Add
operator-Sub
operator*Mul
operator/Div
operator%Rem
operator&BitAnd
operator|BitOr
operator^BitXor
operator<<Shl
operator>>Shr
operator+=AddAssign
operator-=SubAssign
operator*=MulAssign
operator/=DivAssign
operator%=RemAssign
operator&=BitAndAssign
operator|=BitOrAssign
operator^=BitXorAssign
operator<<=ShlAssign
operator>>=ShrAssign

The C++ unary operators below are mapped one-way into the corresponding Rust traits as follows:

C++ APIRust bindings
operator-Neg
operator!Not