daily pastebin goal
31%
SHARE
TWEET

Untitled

a guest Dec 19th, 2018 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use std::os::raw::c_void;
  2. extern {
  3.     // context, data
  4.     fn on_thing_happens(callback: extern fn(*const c_void, u32));
  5. }
  6.  
  7. fn register<F: Fn(u32)>(f: F) {
  8.     extern fn handler<F: Fn(u32)>(f_ptr: *const c_void, val: u32) {
  9.         let f = unsafe { &*(f_ptr as *const F) };
  10.         f(val)
  11.     }
  12.     unsafe {
  13.         on_thing_happens(handler::<F>);
  14.     }
  15. }
  16.  
  17. fn main() {
  18.     fn foo(a: u32) {
  19.         println!("{}", a);
  20.     }
  21.     register(foo);
  22. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top