Guest User

Untitled

a guest
Nov 16th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. pub fn closure_to_ffi<F: Fn(i32, i32) -> i32>(f: F) -> (*mut F, unsafe extern "C" fn(*mut F, i32, i32) -> i32) {
  2. unsafe extern "C" fn call_closure_from_ffi<F: Fn(i32, i32) -> i32>(f: *mut F, a: i32, b: i32) -> i32 {
  3. (*f)(a, b)
  4. }
  5. (Box::into_raw(Box::new(f)), call_closure_from_ffi::<F>)
  6. }
  7.  
  8. pub fn main() {
  9. closure_to_ffi(|x, y| x + y);
  10. }
Add Comment
Please, Sign In to add comment