Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pub fn closure_to_ffi<F: Fn(i32, i32) -> i32>(f: F) -> (*mut F, unsafe extern "C" fn(*mut F, i32, i32) -> i32) {
- unsafe extern "C" fn call_closure_from_ffi<F: Fn(i32, i32) -> i32>(f: *mut F, a: i32, b: i32) -> i32 {
- (*f)(a, b)
- }
- (Box::into_raw(Box::new(f)), call_closure_from_ffi::<F>)
- }
- pub fn main() {
- closure_to_ffi(|x, y| x + y);
- }
Add Comment
Please, Sign In to add comment