mirror of
https://github.com/KaiserY/trpl-zh-cn
synced 2025-04-22 13:38:04 +08:00
14 lines
211 B
Rust
Executable File
14 lines
211 B
Rust
Executable File
fn add_one(x: i32) -> i32 {
|
|
x + 1
|
|
}
|
|
|
|
fn do_twice(f: fn(i32) -> i32, arg: i32) -> i32 {
|
|
f(arg) + f(arg)
|
|
}
|
|
|
|
fn main() {
|
|
let answer = do_twice(add_one, 5);
|
|
|
|
println!("The answer is: {}", answer);
|
|
}
|