Created
December 2, 2018 04:44
-
-
Save toshimasa-nanaki/342af3a0e4705e227c0aa6ddb0b39e2a to your computer and use it in GitHub Desktop.
Rust 関数(関数ポインタ)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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