Open dtolnay opened 4 years ago
Update: cxx 1.0.6 covers the first of the 3 bullets above. We support derive(PartialEq)
\<-> operator==
operator!=
; derive(PartialOrd)
\<-> operator<
operator<=
operator>
operator>=
; and derive(Hash)
\<-> template <> struct std::hash<T>
.
I check for a new cxx
release every morning, every new feature is so helpful! Do you plan to add devive
support to shared enums? It looks like PartialEq
works, but PartialOrd
does not.
derive(PartialOrd, Ord)
for shared enums is fixed in 1.0.9.
What is the current recommended way of overloading operators in C++ for a Rust opaque type (for example the +
operator)? For example, I have:
#[cxx::bridge]
mod ffi {
extern "Rust" {
type Atom;
fn add_atom(at1: &Atom, at2: &Atom) -> Box<Atom>;
}
}
and I want to add something like
rust::cxxbridge1::Box<Atom> operator+(const Atom &other)
{
return add_atom(this, other);
}
to the auto-generated code for struct Atom final : public ::rust::Opaque
.
Many integration opportunities here.
If a shared struct has a #[derive(
PartialEq
orOrd
)] then emit a compatibleoperator ==
,operator !=
,operator <
,operator <=
,operator >
,operator >=
on the type for C++.If an opaque Rust type is written with trait bounds then wire up the corresponding operator for C++ in a way that delegates to Rust's implementation of the operator.
If an opaque C++ type is written with trait bounds then produce a trait impl in Rust that delegates to the corresponding overloaded operator(s) in C++.