Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let test_cb = move |n: i32| {
- n*2
- };
- let mut _test_worker = new(test_cb);
- pub struct Worker {
- ptr: WorkerPtr, // Pointer to the C data structure
- cb: fn(i32) -> i32, // Callback function
- }
- struct WorkerPtr(NonNull<worker>);
- unsafe impl marker::Send for WorkerPtr {}
- struct worker_s {
- void* rust_object; // Pointer to the Rust data structure
- };
- #[no_mangle]
- pub extern fn rust_callback(w: *mut Worker, raw_n: c_int) -> c_int {
- let n = raw_n as i32;
- println!("rust_callback: {}", n);
- unsafe {
- let out = (*w).trigger_callback(n);
- out as c_int
- }
- }
- worker_new: worker = 0x7f9834d000c0
- worker_set_rust_object: worker = 0x7f9834d000c0 rust_object = 0x10ca21000
- trigger_callback: worker = 0x7f9834d000c0 rust_object = 0x10ca21000
- rust_callback: 100
- trigger_callback: 100
- got: 200
Add Comment
Please, Sign In to add comment