Skip to content

Instantly share code, notes, and snippets.

@amuxtux
Forked from eevee/gist:3970206
Created November 15, 2012 05:38
Show Gist options
  • Save amuxtux/4076837 to your computer and use it in GitHub Desktop.
Save amuxtux/4076837 to your computer and use it in GitHub Desktop.
passing a rust function as a C callback
extern fn status_foreach_callback(path: *c_char, stat: c_uint, payload: *c_void) -> c_int unsafe {
let path_str = str::raw::from_c_str(path);
let f: *fn(&str, uint) = cast::reinterpret_cast(&payload);
(*f)(path_str, stat as uint);
return 0;
}
// ...
impl Repository {
fn for_status(f: fn(&str, uint)) unsafe {
c::git_status_foreach(self.c_repository, status_foreach_callback, cast::reinterpret_cast(&ptr::addr_of(&f)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment