1 #![crate_name = "externcallback"] 2 #![crate_type = "lib"] 3 #![feature(rustc_private)] 4 5 extern crate libc; 6 7 pub mod rustrt { 8 extern crate libc; 9 10 #[link(name = "rust_test_helpers", kind = "static")] 11 extern "C" { rust_dbg_call( cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t, data: libc::uintptr_t, ) -> libc::uintptr_t12 pub fn rust_dbg_call( 13 cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t, 14 data: libc::uintptr_t, 15 ) -> libc::uintptr_t; 16 } 17 } 18 fact(n: libc::uintptr_t) -> libc::uintptr_t19pub fn fact(n: libc::uintptr_t) -> libc::uintptr_t { 20 unsafe { 21 println!("n = {}", n); 22 rustrt::rust_dbg_call(cb, n) 23 } 24 } 25 cb(data: libc::uintptr_t) -> libc::uintptr_t26pub extern "C" fn cb(data: libc::uintptr_t) -> libc::uintptr_t { 27 if data == 1 { data } else { fact(data - 1) * data } 28 } 29