Skip to content

4.20. Drop (1.9) #169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions 1.9/ja/book/drop.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<!-- Now that we’ve discussed traits, let’s talk about a particular trait provided -->
<!-- by the Rust standard library, [`Drop`][drop]. The `Drop` trait provides a way -->
<!-- to run some code when a value goes out of scope. For example: -->
トレイトについて学びましたので、Rustの標準ライブラリによって提供されている具体的なトレイト [`Drop`][drop]について説明しましょう。
`Drop` トレイトは値がスコープ外になった時にコードを実行する方法を提供します:
トレイトについて学びましたので、Rustの標準ライブラリによって提供されている具体的なトレイト [`Drop`][drop] について説明しましょう。
`Drop` トレイトは値がスコープ外になった時にコードを実行する方法を提供します

[drop]: ../std/ops/trait.Drop.html

Expand All @@ -32,13 +32,15 @@ fn main() {
<!-- run. `Drop` has one method, which is also called `drop()`. It takes a mutable -->
<!-- reference to `self`. -->
`x` が `main()` の終わりでスコープ外になった時、 `Drop` のコードが実行されます。
`Drop` は `drop()` と呼ばれるミュータブルな `self` への参照を引数に取るメソッドを持っています。
`Drop` にはメソッドは1つだけあり、それもまた `drop()` と呼ばれます。
ミュータブルな `self` への参照を引数に取ります。

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

```rust
struct Firework {
Expand All @@ -58,25 +60,27 @@ fn main() {
```

<!-- This will output: -->
このコードは以下の様な出力をします:
このコードは以下のように出力します。

```text
BOOM times 100!!!
BOOM times 1!!!
```

<!-- The TNT goes off before the firecracker does, because it was declared -->
<!-- The `tnt` goes off before the `firecracker` does, because it was declared -->
<!-- afterwards. Last in, first out. -->
TNTが爆竹(firecracker)が鳴る前に爆発してしまいました、これはTNTが定義されたのは爆竹よりも後だったことによります。
`tnt` が `firecracker` (爆竹)が鳴る前に爆発してしまいました。
これはTNTが定義されたのは爆竹よりも後だったためです。
ラストイン・ファーストアウトです。

<!-- So what is `Drop` good for? Generally, `Drop` is used to clean up any resources -->
<!-- associated with a `struct`. For example, the [`Arc<T>` type][arc] is a -->
<!-- reference-counted type. When `Drop` is called, it will decrement the reference -->
<!-- count, and if the total number of references is zero, will clean up the -->
<!-- underlying value. -->
`Drop` は何をするのに適しているのでしょうか?一般的に `Drop` は `struct` に関連付けられているリソースのクリーンアップに利用されます。
たとえば、 [`Arc<T>` 型][arc] は参照カウントを行う型です。 `Drop` が呼ばれると、参照カウントがデクリメントされ、
もし参照の合計数が0になっていたら、内包している値がクリーンアップされます。
`Drop` は何をするのに向いているのでしょうか?
一般的に `Drop` は `struct` に関連付けられているリソースのクリーンアップに使われます。
たとえば [`Arc<T>` 型][arc] は参照カウントを行う型です。
`Drop` が呼ばれると、参照カウントがデクリメントされ、もし参照の合計数が0になっていたら、内包している値がクリーンアップされます。

[arc]: ../std/sync/struct.Arc.html
12 changes: 0 additions & 12 deletions diff-1.6.0..1.9.0/src/doc/book/drop.md

This file was deleted.