Skip to content

Commit 9b0fbea

Browse files
committed
Update translation of the word 'return'
1 parent d5a4367 commit 9b0fbea

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@
288288
-->
289289
- [トレイト](trait.md)
290290
- [導出(Derive)](trait/derive.md)
291-
- [`dyn`を利用してトレイトをリターンする](trait/dyn.md)
291+
- [`dyn`を利用してトレイトを返す](trait/dyn.md)
292292
- [演算子のオーバーロード](trait/ops.md)
293293
- [メモリ解放](trait/drop.md)
294294
- [イテレータ](trait/iter.md)

src/trait/dyn.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
<!--
22
# Returning Traits with `dyn`
33
-->
4-
# `dyn`を利用してトレイトをリターンする
4+
# `dyn`を利用してトレイトを返す
55

66
<!--
77
The Rust compiler needs to know how much space every function's return type requires. This means all your functions have to return a concrete type. Unlike other languages, if you have a trait like `Animal`, you can't write a function that returns `Animal`, because its different implementations will need different amounts of memory.
88
-->
99
Rustのコンパイラはあらゆる関数のリターン型に必要なスペースを知っておく必要があります。
10-
つまり、すべての関数は具体的な型をリターンする必要があるのです
11-
他の言語と違って、`Animal`のようなトレイトがある場合に、`Animal`をリターンする関数を書くことはできません
10+
つまり、すべての関数は具体的な型を返す必要があるのです
11+
他の言語と違って、`Animal`のようなトレイトがある場合に、`Animal`を返す関数を書くことはできません
1212
なぜなら、そのトレイトの異なる実装はそれぞれ別の量のメモリを必要とするからです。
1313

1414
<!--
1515
However, there's an easy workaround. Instead of returning a trait object directly, our functions return a `Box` which _contains_ some `Animal`. A `box` is just a reference to some memory in the heap. Because a reference has a statically-known size, and the compiler can guarantee it points to a heap-allocated `Animal`, we can return a trait from our function!
1616
-->
1717
しかし、簡単な回避策があります。
18-
直接トレイトオブジェクトをリターンする代わりに`Animal`_含む_ `Box`をリターンするのです
18+
直接トレイトオブジェクトを返す代わりに`Animal`_含む_ `Box`を返すのです
1919
`Box`はヒープ中のメモリへの単なる参照です。
20-
参照のサイズは静的に知ることができ、コンパイラは参照がヒープに割り当てられた`Animal`を指していると保証できるので、私たちは関数からトレイトをリターンできます
20+
参照のサイズは静的に知ることができ、コンパイラは参照がヒープに割り当てられた`Animal`を指していると保証できるので、私たちは関数からトレイトを返すことができます
2121

2222
<!--
2323
Rust tries to be as explicit as possible whenever it allocates memory on the heap. So if your function returns a pointer-to-trait-on-heap in this way, you need to write the return type with the `dyn` keyword, e.g. `Box<dyn Animal>`.
2424
-->
2525
ヒープにメモリを割り当てる際、Rustは可能な限り明示的であろうとします。
26-
なので、もしあなたの関数がヒープ上のトレイトへのポインタをリターンする場合、例えば`Box<dyn Animal>`のように、リターン型に`dyn`キーワードをつける必要があります。
26+
なので、もしあなたの関数がヒープ上のトレイトへのポインタを返す場合、例えば`Box<dyn Animal>`のように、リターン型に`dyn`キーワードをつける必要があります。
2727

2828
```rust,editable
2929
struct Sheep {}
@@ -52,7 +52,7 @@ impl Animal for Cow {
5252
}
5353
5454
// Returns some struct that implements Animal, but we don't know which one at compile time.
55-
// Animalを実装した何らかの構造体をリターンする
55+
// Animalを実装した何らかの構造体を返す
5656
// ただし、コンパイル時にはどの実装か分からない。
5757
fn random_animal(random_number: f64) -> Box<dyn Animal> {
5858
if random_number < 0.5 {

0 commit comments

Comments
 (0)