As the error implies, the function type that you try to pass as a callback
is incorrect.

The problem is that because the callback is called from C it ought to be
"compatible" with C, thus the "extern" bit.

Rather than defining an anonymous function, you need to write an "extern
fn" function (with a name), so that the function (at low-level) have a
compatible ABI with C.

-- Matthieu


On Sat, May 11, 2013 at 3:04 AM, Skirmantas Kligys <
skirmantas.kli...@gmail.com> wrote:

> I am trying to write a native wrapper for
>
> https://github.com/pascalj/rust-expat
>
> (BTW, if there is a native Rust XML parser, I am interested to hear
> about it, did not find it).  I have trouble calling back into Rust
> from C code:
>
> fn set_element_handlers(parser: expat::XML_Parser, start_handler:
> &fn(tag: &str, attrs: &[@str]), end_handler: &fn(tag: &str)) {
>   let start_cb = |_user_data: *c_void, c_name: *c_char, _c_attrs:
> **c_char| {
>     unsafe {
>       let name = str::raw::from_c_str(c_name);
>       start_handler(name, []);
>     }
>   };
>
>   let end_cb = |_user_data: *c_void, c_name: *c_char| {
>     unsafe {
>       let name = str::raw::from_c_str(c_name);
>       end_handler(name);
>     }
>   };
>
>   expat::XML_SetElementHandler(parser, start_cb, end_cb);
> }
>
> This says that it saw &fn... instead of expected extern fn for the
> second and third parameter.  Any ideas how to do this?
>
> Thanks.
> _______________________________________________
> Rust-dev mailing list
> Rust-dev@mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev
>
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to