-
-
Save amuxtux/4076837 to your computer and use it in GitHub Desktop.
passing a rust function as a C callback
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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