Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::os::raw::c_void;
- extern {
- fn register_callback(callback: extern fn(*const c_void, u32), user: *const c_void);
- }
- fn register<F: Fn(u32)>(f: F) {
- extern fn handler<F: Fn(u32)>(f_ptr: *const c_void, val: u32) {
- let f = unsafe { &*(f_ptr as *const F) };
- f(val)
- }
- unsafe {
- register_callback(handler::<F>, Box::into_raw(Box::new(f)) as *const c_void);
- }
- }
Add Comment
Please, Sign In to add comment