Support calling Rust methods from C++
These methods can be declared in the bridge by naming the first
argument self and making it a reference to the containing class, e.g.,
fn get(self: &R) -> usize;
fn set(self: &mut R, n: usize);
This syntax requires Rust 1.43.
diff --git a/demo-rs/src/main.rs b/demo-rs/src/main.rs
index 759bbe1..713a1d1 100644
--- a/demo-rs/src/main.rs
+++ b/demo-rs/src/main.rs
@@ -19,6 +19,7 @@
extern "Rust" {
type ThingR;
fn print_r(r: &ThingR);
+ fn print(self: &ThingR);
}
}
@@ -28,6 +29,12 @@
println!("called back with r={}", r.0);
}
+impl ThingR {
+ fn print(&self) {
+ println!("method called back with r={}", self.0);
+ }
+}
+
fn main() {
let x = ffi::make_demo("demo of cxx::bridge");
println!("this is a {}", x.as_ref().unwrap().get_name());