How to define rust function which is a callback as a C function?

Hi, how to declare function (GIOFunc) which is specified as following:

pub type GIOFunc =
    Option<unsafe extern "C" fn(*mut GIOChannel, GIOCondition, gpointer) -> gboolean>;

And it is used here:

pub fn g_io_add_watch(
        channel: *mut GIOChannel,
        condition: GIOCondition,
        func: GIOFunc,//here, how to define that function?
        user_data: gpointer,
    ) -> c_uint;

You literally go:

unsafe extern "C" fn cback(chan: *mut GIOChannel, cond: GIOCondition, ptr: gpointer) -> gboolean {
    // Code here
}

Thanks, I seem to have a mental block. When I code C/C++ all's good. When I learn rust I seem to be doing OK.
That is not the case when I start using unsafe rust.
Thanks again.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.