Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created November 25, 2021 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/0c50feb83babb4df431f7d18afa85ca8 to your computer and use it in GitHub Desktop.
Save rust-play/0c50feb83babb4df431f7d18afa85ca8 to your computer and use it in GitHub Desktop.
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