27 lines
500 B
Rust
27 lines
500 B
Rust
//@ run-pass
|
|
|
|
#[link(name = "rust_test_helpers", kind = "static")]
|
|
extern "C" {
|
|
pub fn rust_dbg_call(
|
|
cb: extern "C" fn(u64) -> u64,
|
|
data: u64,
|
|
) -> u64;
|
|
}
|
|
|
|
extern "C" fn cb(data: u64) -> u64 {
|
|
if data == 1 { data } else { fact(data - 1) * data }
|
|
}
|
|
|
|
fn fact(n: u64) -> u64 {
|
|
unsafe {
|
|
println!("n = {}", n);
|
|
rust_dbg_call(cb, n)
|
|
}
|
|
}
|
|
|
|
pub fn main() {
|
|
let result = fact(10);
|
|
println!("result = {}", result);
|
|
assert_eq!(result, 3628800);
|
|
}
|