I have the following C function:
typedef void (*button_handler_fn_t)();
void set_button_handler(uint32_t button_no, button_handler_fn_t handler_fn);
The second parameter is a C function that takes no parameters and returns void
.
I want to call this C function from Rust, passing in a Rust function. bindgen
generates the following bindings which I then import in my Rust program:
pub type button_handler_fn_t = ::core::option::Option<unsafe extern "C" fn()>;
extern "C" {
pub fn set_button_handler(button_no: u32, handler_fn: button_handler_fn_t);
}
How can I make a function call?
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
unsafe fn callback_button_0() {
svc_leds_toggle(0);
}
fn main() -> ! {
set_button_handler(0, callback_button_0);
^^^^^^^^^^^^^^^^^ expected enum `core::option::Option`, found fn item
= note: expected type `core::option::Option<unsafe extern "C" fn()>`
found type `unsafe fn() {callback_button_0}`