I would like to create a callback function. The following code is not working but it shows what I want to do. Here is the link of my broken program in Rust Playground.
fn use_callback(callback: fn()) -> i32 {
callback()
}
fn callback() -> i32 {
2
}
fn main() {
println!("Result: {:?}", use_callback(callback));
}
The expected result should be Result: 2.
You just need to change the type of callback in the
use_callbackfunction to a function pointer that returns ani32.rust playground