Skip to content

Commit fa7880f

Browse files
committed
Roughly Translated
1 parent f46c601 commit fa7880f

File tree

1 file changed

+34
-21
lines changed

1 file changed

+34
-21
lines changed

1.6/ja/book/drop.md

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
% Drop
2+
<!-- % Drop -->
23

3-
Now that we’ve discussed traits, let’s talk about a particular trait provided
4-
by the Rust standard library, [`Drop`][drop]. The `Drop` trait provides a way
5-
to run some code when a value goes out of scope. For example:
4+
<!-- Now that we’ve discussed traits, let’s talk about a particular trait provided -->
5+
<!-- by the Rust standard library, [`Drop`][drop]. The `Drop` trait provides a way -->
6+
<!-- to run some code when a value goes out of scope. For example: -->
7+
トレイトについて学びましたので、Rustの標準ライブラリによって提供されている具体的なトレイト [`Drop`][drop]について説明しましょう。
8+
`Drop` トレイトは値がスコープ外になった時にコードを実行する方法を提供します:
69

7-
[drop]: ../std/ops/trait.Drop.html
10+
[ドロップ]: ../std/ops/trait.Drop.html
811

912
```rust
1013
struct HasDrop;
@@ -18,18 +21,22 @@ impl Drop for HasDrop {
1821
fn main() {
1922
let x = HasDrop;
2023

21-
// do stuff
24+
// いくつかの処理
2225

23-
} // x goes out of scope here
26+
} // x はここでスコープ外になります
2427
```
2528

26-
When `x` goes out of scope at the end of `main()`, the code for `Drop` will
27-
run. `Drop` has one method, which is also called `drop()`. It takes a mutable
28-
reference to `self`.
29+
<!-- When `x` goes out of scope at the end of `main()`, the code for `Drop` will -->
30+
<!-- run. `Drop` has one method, which is also called `drop()`. It takes a mutable -->
31+
<!-- reference to `self`. -->
32+
`x``main()` の終わりでスコープ外になった時、 `Drop` のコードが実行されます。
33+
`Drop``drop()` と呼ばれるミュータブルな `self` への参照を引数に取るメソッドを持っています。
2934

30-
That’s it! The mechanics of `Drop` are very simple, but there are some
31-
subtleties. For example, values are dropped in the opposite order they are
32-
declared. Here’s another example:
35+
<!-- That’s it! The mechanics of `Drop` are very simple, but there are some -->
36+
<!-- subtleties. For example, values are dropped in the opposite order they are -->
37+
<!-- declared. Here’s another example: -->
38+
これだけです! `Drop` のメカニズムは非常にシンプルです、しかし少しだけ重要な点があります。
39+
たとえば、値がドロップされる順序は、それらが定義された順序と反対の順序になります:
3340

3441
```rust
3542
struct Firework {
@@ -48,20 +55,26 @@ fn main() {
4855
}
4956
```
5057

51-
This will output:
58+
<!-- This will output: -->
59+
このコードは以下の様な出力をします:
5260

5361
```text
5462
BOOM times 100!!!
5563
BOOM times 1!!!
5664
```
5765

58-
The TNT goes off before the firecracker does, because it was declared
59-
afterwards. Last in, first out.
60-
61-
So what is `Drop` good for? Generally, `Drop` is used to clean up any resources
62-
associated with a `struct`. For example, the [`Arc<T>` type][arc] is a
63-
reference-counted type. When `Drop` is called, it will decrement the reference
64-
count, and if the total number of references is zero, will clean up the
65-
underlying value.
66+
<!-- The TNT goes off before the firecracker does, because it was declared -->
67+
<!-- afterwards. Last in, first out. -->
68+
TNTが爆竹が鳴る前に爆発してしまいました、これはTNTが定義されたのは爆竹よりも後だったことによります。
69+
ラストイン・ファーストアウトです。
70+
71+
<!-- So what is `Drop` good for? Generally, `Drop` is used to clean up any resources -->
72+
<!-- associated with a `struct`. For example, the [`Arc<T>` type][arc] is a -->
73+
<!-- reference-counted type. When `Drop` is called, it will decrement the reference -->
74+
<!-- count, and if the total number of references is zero, will clean up the -->
75+
<!-- underlying value. -->
76+
`Drop` は何をするのに適しているのでしょうか?一般的に `Drop``struct` に関連付けられているリソースのクリーンアップに利用されます。
77+
たとえば、 [`Arc<T>`][arc] は参照カウントを行う型です。 `Drop` が呼ばれると、参照カウントがデクリメントされ、
78+
もし参照の合計数が0になっていたら、内包している値がクリーンアップされます。
6679

6780
[arc]: ../std/sync/struct.Arc.html

0 commit comments

Comments
 (0)