Skip to content

Instantly share code, notes, and snippets.

@toshimasa-nanaki
Created December 2, 2018 04:44
Show Gist options
  • Save toshimasa-nanaki/342af3a0e4705e227c0aa6ddb0b39e2a to your computer and use it in GitHub Desktop.
Save toshimasa-nanaki/342af3a0e4705e227c0aa6ddb0b39e2a to your computer and use it in GitHub Desktop.
Rust 関数(関数ポインタ)
fn main() {
let function: fn(i32) -> i32 = times_number; //型として「fn(i32) -> i32」を宣言。
println!("When x is doubled, {}.", function(7)); //上で宣言した変数を利用して関数呼び出し
}
fn times_number(x: i32) -> i32 {
x * 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment