macro_rules! send_fn_ptr {
($sig:ty, $var:expr) => { ... };
}Expand description
This macro creates a Function Pointer that is Send and guaranteed to have the same representation in memory as a raw function pointer would. (Meaning its size is usize)
ยงExample
use std::ffi::c_void;
use sync_ptr::send_fn_ptr;
use sync_ptr::SendFnPtr;
extern "C" fn test_function() -> u64 {
123456u64
}
fn some_function() {
let test_fn_ptr = send_fn_ptr!(extern "C" fn() -> u64, test_function);
//Type of test_fn_ptr is SendFnPtr<extern "C" fn() -> u64>
std::thread::spawn(move || {
assert_eq!(test_fn_ptr(), test_function());
}).join().unwrap();
}