This is how C API looks
void mosquitto_connect_callback_set(struct mosquitto *mosq, void (*on_connect)(struct mosquitto *, void *, int));
rust-bindgen
has generated this for me
pub fn mosquitto_connect_callback_set(mosq: *mut Struct_mosquitto,
on_connect:
::std::option::Option<extern "C" fn(arg1:
*mut Struct_mosquitto,
arg2:
*mut ::libc::c_void,
arg3:
::libc::c_int) -> ()>)
How do I create a rust callback function to pass to on_connect
parameter in the above rust binding?
Have you read The Rust Programming Language, specifically the section about FFI titled Callbacks from C code to Rust functions?
The example from there is
For your specific case, you already know the specific type of function you need:
And then use it like