Declare function to xmllib2 using rust-libxml

Working on the scxml interpreter, I want to declare a function to the xml path context.

It looks like I'll need this function signature:

unsafe extern "C" fn(ctxt: xmlXPathParserContextPtr, nargs: ::std::os::raw::c_int)

I'd like this function to be written in Rust. However, it looks like a function signature for that is

unsafe extern "C" fn(ctxt: xmlXPathParserContextPtr, nargs: ::std::os::raw::c_int) {}

I'm trying to use this as follows:

let funcname = CString::new("In").unwrap();
let func = Some(in_func);
let rslt = unsafe {
     xmlXPathRegisterFunc(context.as_ptr(), funcname.as_ptr() as *const u8, func)
};

which gives this error:

error[E0308]: mismatched types
      |
277   |                 xmlXPathRegisterFunc(context.as_ptr(), funcname.as_ptr() as *const u8, func)
      |                 -------------------- arguments to this function are incorrect          ^^^^ expected `Option<unsafe extern "C" fn(..., ...)>`, found `Option<unsafe extern "C" fn(..., ...) {in_func}>`
      |
      = note: expected enum `Option<unsafe extern "C" fn(_, _)>`
                 found enum `Option<unsafe extern "C" fn(_, _) {in_func}>`
note: function defined here
     --> libxml-0.3.3/src/bindings.rs:20561:10
      |
20561 |   pub fn xmlXPathRegisterFunc(
      |          ^^^^^^^^^^^^^^^^^^^^

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.