Closed hurricane-socrates closed 5 months ago
Thanks for the update. Somehow I didn't get notified of the label addtions. I've moved on from this problem as being unsolvable given my level of Rust knowledge, though I do appreciate the "help wanted" label.
You could explicitly cast the function item as a function pointer:
let in_func = in_func as unsafe extern "C" fn(ctxt: xmlXPathParserContextPtr, nargs: ::std::os::raw::c_int);
let func = Some(in_func);
Or use type coercion instead:
let func: xmlXPathFunction = Some(in_func);
A minimal example following the OP would be:
#[test]
fn test_rust_xml_xpath_register_func(){
extern "C" fn in_func(ctxt: xmlXPathParserContextPtr, nargs: ::std::os::raw::c_int) {}
let context_ptr = std::ptr::null_mut();
let funcname = std::ffi::CString::new("In").unwrap();
// let in_func = in_func as unsafe extern "C" fn(ctxt: xmlXPathParserContextPtr, nargs: ::std::os::raw::c_int);
// let func = Some(in_func);
let func: xmlXPathFunction = Some(in_func);
let rslt = unsafe {
xmlXPathRegisterFunc(context_ptr, funcname.as_ptr() as *const u8, func)
};
}
Thanks! I willl take a look at that technique.
This is a question also asked on rust-users
I'm working on an scxml interpreter. I want to declare a function to the xml path context. I'd appreciate some guidance.
It looks like I'll need this function signature:
I'd like this function to be written in Rust. However, it looks like a function signature for that is
I'm trying to use this as follows:
which gives this error: