Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created Nov 25, 2021
Embed
What would you like to do?
Code shared from the Rust Playground
fn hoge(x: i32) -> i32 {
x + 1
}
fn fuga(y: i32) -> i32 {
y * 2
}
fn main() {
let mut f: Box<dyn Fn(i32) -> i32> = Box::new(hoge);
println!("{}", f(15));
f = Box::new(fuga);
println!("{}", f(20));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment