forked from dtolnay/cxx
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.rs
39 lines (32 loc) · 809 Bytes
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#[cxx::bridge(namespace = org::example)]
mod ffi {
struct SharedThing {
z: i32,
y: Box<ThingR>,
x: UniquePtr<ThingC>,
}
extern "C" {
include!("demo/include/demo.h");
type ThingC;
fn make_demo(appname: &str) -> UniquePtr<ThingC>;
fn get_name(thing: &ThingC) -> &CxxString;
fn do_thing(state: SharedThing);
}
extern "Rust" {
type ThingR;
fn print_r(r: &ThingR);
}
}
pub struct ThingR(usize);
fn print_r(r: &ThingR) {
println!("called back with r={}", r.0);
}
fn main() {
let x = ffi::make_demo("demo of cxx::bridge");
println!("this is a {}", ffi::get_name(x.as_ref().unwrap()));
ffi::do_thing(ffi::SharedThing {
z: 222,
y: Box::new(ThingR(333)),
x,
});
}