Open dtolnay opened 3 years ago
Maybe like this:
#[cxx::bridge]
mod ffi {
unsafe extern "C++" {
type dynamic;
#[ref_qualifier = "&"] // or "&&"
fn getDouble(&self) -> f64;
}
}
The attribute uses the terminology from https://en.cppreference.com/w/cpp/language/member_functions#ref-qualified_member_functions.
For example, this method from
folly::dynamic
: https://github.com/facebook/folly/blob/f604b03c5e0305860326f77c4562cba27547db38/folly/dynamic.h#L311Simplified, the data structure looks like:
If we currently try binding this from CXX as follows, then it fails to compile.
The generated code contains something along the lines of: