@@ -37,11 +37,12 @@ fn main() {
37
37
let outer_var = 42;
38
38
39
39
// A regular function can't refer to variables in the enclosing environment
40
- // Increment via closures and functions.
41
- // 関数とクロージャのそれぞれで数値をインクリメントする
40
+ // 通常の関数は周辺の環境の変数を参照できない。
42
41
//fn function(i: i32) -> i32 { i + outer_var }
43
42
// TODO: uncomment the line above and see the compiler error. The compiler
44
43
// suggests that we define a closure instead.
44
+ // TODO: 上の行をアンコメントしてコンパイラエラーを見てみよう。
45
+ // 代わりにクロージャを定義することをコンパイラが提案してくれる。
45
46
46
47
// Closures are anonymous, here we are binding them to references
47
48
// Annotation is identical to function annotation but is optional
@@ -58,8 +59,10 @@ fn main() {
58
59
println!("closure_annotated: {}", closure_annotated(1));
59
60
println!("closure_inferred: {}", closure_inferred(1));
60
61
// Once closure's type has been inferred, it cannot be inferred again with another type.
62
+ // クロージャの型が一度推論されると、別の型にあらためて推論することはできない。
61
63
//println!("cannot reuse closure_inferred with another type: {}", closure_inferred(42i64));
62
64
// TODO: uncomment the line above and see the compiler error.
65
+ // TODO: 上の行をアンコメントしてコンパイルエラーを見てみよう。
63
66
64
67
// A closure taking no arguments which returns an `i32`.
65
68
// The return type is inferred.
0 commit comments