Guest User

Untitled

a guest
Dec 19th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. use std::os::raw::c_void;
  2. extern {
  3. fn register_callback(callback: extern fn(*const c_void, u32), user: *const c_void);
  4. }
  5.  
  6. fn register<F: Fn(u32)>(f: F) {
  7. extern fn handler<F: Fn(u32)>(f_ptr: *const c_void, val: u32) {
  8. let f = unsafe { &*(f_ptr as *const F) };
  9. f(val)
  10. }
  11. unsafe {
  12. register_callback(handler::<F>, Box::into_raw(Box::new(f)) as *const c_void);
  13. }
  14. }
Add Comment
Please, Sign In to add comment