Skip to content

Commit fe18028

Browse files
authored
Merge pull request #222 from KeenS/1.9-closures
4.23 Closures (1.9)
2 parents 866f60d + d708452 commit fe18028

File tree

2 files changed

+9
-73
lines changed

2 files changed

+9
-73
lines changed

1.9/ja/book/closures.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,11 @@ assert_eq!(5, num);
267267

268268
<!-- Rust’s implementation of closures is a bit different than other languages. They -->
269269
<!-- are effectively syntax sugar for traits. You’ll want to make sure to have read -->
270-
<!-- the [traits chapter][traits] before this one, as well as the chapter on [trait -->
270+
<!-- the [traits][traits] section before this one, as well as the section on [trait -->
271271
<!-- objects][trait-objects]. -->
272272
Rustにおけるクロージャの実装は他の言語とは少し異なります。
273273
Rustにおけるクロージャは実質的にトレイトへの糖衣構文です。
274-
続きの説明を読む前に [トレイト][traits][トレイトオブジェクト][trait-objects] についてのチャプターを学ぶ前に読みたくなるでしょう
274+
続きの説明を読む前に [トレイト][traits][トレイトオブジェクト][trait-objects] についてのセクションを学ぶ前に読みたくなるでしょう
275275

276276
[traits]: traits.html
277277
[trait-objects]: trait-objects.html
@@ -330,9 +330,9 @@ Rustは環境用の構造体を作成し、 適切なトレイトを `impl` し
330330
# クロージャを引数に取る
331331

332332
<!-- Now that we know that closures are traits, we already know how to accept and -->
333-
<!-- return closures: just like any other trait! -->
333+
<!-- return closures: the same as any other trait! -->
334334
クロージャが実際にはトレイトであることを学んだので、
335-
クロージャを引数としたり返り値としたりする方法を既に知っていることになります: 通常のトレイトと同様に行うのです!
335+
クロージャを引数としたり返り値としたりする方法を既に知っていることになります: 通常のトレイトと全く同様に行うのです!
336336

337337
<!-- This also means that we can choose static vs dynamic dispatch as well. First, -->
338338
<!-- let’s write a function which takes something callable, calls it, and returns -->
@@ -352,7 +352,7 @@ let answer = call_with_one(|x| x + 2);
352352
assert_eq!(3, answer);
353353
```
354354

355-
<!-- We pass our closure, `|x| x + 2`, to `call_with_one`. It just does what it -->
355+
<!-- We pass our closure, `|x| x + 2`, to `call_with_one`. It does what it -->
356356
<!-- suggests: it calls the closure, giving it `1` as an argument. -->
357357
クロージャ `|x| x + 2``call_with_one` に渡しました。
358358
`call_with_one` はその関数名から推測される処理を行います: クロージャに `1` を与えて呼び出します。
@@ -479,14 +479,13 @@ assert_eq!(6, answer);
479479
このコードは以下の長いエラーを発生させます:
480480

481481
```text
482-
error: the trait `core::marker::Sized` is not implemented for the type
483-
`core::ops::Fn(i32) -> i32` [E0277]
482+
error: the trait bound `core::ops::Fn(i32) -> i32 : core::marker::Sized` is not satisfied [E0277]
484483
fn factory() -> (Fn(i32) -> i32) {
485484
^~~~~~~~~~~~~~~~
486485
note: `core::ops::Fn(i32) -> i32` does not have a constant size known at compile-time
487486
fn factory() -> (Fn(i32) -> i32) {
488487
^~~~~~~~~~~~~~~~
489-
error: the trait `core::marker::Sized` is not implemented for the type `core::ops::Fn(i32) -> i32` [E0277]
488+
error: the trait bound `core::ops::Fn(i32) -> i32 : core::marker::Sized` is not satisfied [E0277]
490489
let f = factory();
491490
^
492491
note: `core::ops::Fn(i32) -> i32` does not have a constant size known at compile-time
@@ -570,7 +569,7 @@ error: mismatched types:
570569

571570

572571
<!-- Because each closure generates its own environment `struct` and implementation -->
573-
<!-- of `Fn` and friends, these types are anonymous. They exist just solely for -->
572+
<!-- of `Fn` and friends, these types are anonymous. They exist solely for -->
574573
<!-- this closure. So Rust shows them as `closure@<anon>`, rather than some -->
575574
<!-- autogenerated name. -->
576575
それぞれのクロージャはそれぞれの環境用の `struct` を生成し、
@@ -642,7 +641,7 @@ assert_eq!(6, answer);
642641
```
643642

644643
<!-- By making the inner closure a `move Fn`, we create a new stack frame for our -->
645-
<!-- closure. By `Box`ing it up, we’ve given it a known size, and allowing it to -->
644+
<!-- closure. By `Box`ing it up, we’ve given it a known size, allowing it to -->
646645
<!-- escape our stack frame. -->
647646
`factory()` 内のクロージャを `move Fn` にすることで、新しいスタックフレームをクロージャのために生成します。
648647
そしてボックス化することによって、既知のサイズとなり、現在のスタックフレームから抜けることが可能になります。

diff-1.6.0..1.9.0/src/doc/book/closures.md

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)