Pass function with parameter as an argument
fn main() { call(hello); } fn hello(text: &str) { println!("Hello {}", text); } fn call(my_function: fn(text: &str) -> ()) { my_function("Foo"); my_function("Bar"); }
Hello Foo
Hello Bar
Press ← or → to navigate between chapters
Press S or / to search in the book
Press ? to show this help
Press Esc to hide this help
fn main() { call(hello); } fn hello(text: &str) { println!("Hello {}", text); } fn call(my_function: fn(text: &str) -> ()) { my_function("Foo"); my_function("Bar"); }
Hello Foo
Hello Bar