mirror of https://github.com/KaiserY/trpl-zh-cn
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
16 lines
346 B
16 lines
346 B
3 months ago
|
fn main() {
|
||
|
let handlers = vec![returns_closure(), returns_initialized_closure(123)];
|
||
|
for handler in handlers {
|
||
|
let output = handler(5);
|
||
|
println!("{output}");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fn returns_closure() -> impl Fn(i32) -> i32 {
|
||
|
|x| x + 1
|
||
|
}
|
||
|
|
||
|
fn returns_initialized_closure(init: i32) -> impl Fn(i32) -> i32 {
|
||
|
move |x| x + init
|
||
|
}
|