Skip to content

Commit 549e1e4

Browse files
committed
static_lifetime.md > Trait bound の節を翻訳
1 parent 06e13ab commit 549e1e4

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/scope/lifetime/static_lifetime.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Both are related but subtly different and this is a common source for
2222
confusion when learning Rust. Here are some examples for each situation:
2323
-->
2424
2つの状況における`static`は微妙に異なる意味を持っており、Rustを学ぶときの混乱の元になっています。
25-
いくつかの例とともにそれぞれの状況について見てみましょう
25+
いくつかの例とともにそれぞれの使い方を見てみましょう
2626

2727
<!--
2828
## Reference lifetime
@@ -35,7 +35,7 @@ the reference lives for the entire lifetime of the running program.
3535
It can still be coerced to a shorter lifetime.
3636
-->
3737
参照のライフタイムが`'static`であることは、参照が指し示すデータがプログラムの実行中に渡って生き続けることを示します。
38-
また、より短いライフタイムに強制することも可能です
38+
また、より短いライフタイムに圧縮することも可能です
3939

4040
<!--
4141
There are two ways to make a variable with `'static` lifetime, and both
@@ -98,15 +98,25 @@ fn main() {
9898
}
9999
```
100100

101+
<!--
101102
## Trait bound
103+
-->
104+
## トレイト境界
102105

106+
<!--
103107
As a trait bound, it means the type does not contain any non-static
104108
references. Eg. the receiver can hold on to the type for as long as
105109
they want and it will never become invalid until they drop it.
110+
-->
111+
トレイト境界としての`'static`は型が非静的な参照を含まないことを意味します。
112+
言い換えると、レシーバはその型をいくらでも長く保持することができ、意図的にドロップするまでは決して無効になることはないということです。
106113

114+
<!--
107115
It's important to understand this means that any owned data always passes
108116
a `'static` lifetime bound, but a reference to that owned data generally
109117
does not:
118+
-->
119+
ここで注意しなければいけないのは、所有権のあるデータが`'static`ライフタイム境界をパスするとしても、そのデータへの参照は`'static`ライフタイム境界をパスしないということです。
110120

111121
```rust,editable,compile_fail
112122
use std::fmt::Debug;
@@ -117,26 +127,35 @@ fn print_it( input: impl Debug + 'static ) {
117127
118128
fn main() {
119129
// i is owned and contains no references, thus it's 'static:
130+
// i は所有されていて、かつ参照を含まないので 'static
120131
let i = 5;
121132
print_it(i);
122133
123134
// oops, &i only has the lifetime defined by the scope of
124135
// main(), so it's not 'static:
136+
// おっと、&i は main() で定義されたライフタイムしかもたないため 'static ではない
125137
print_it(&i);
126138
}
127139
```
140+
<!--
128141
The compiler will tell you:
142+
-->
143+
コンパイラのメッセージはこのようになります、
129144
```ignore
130145
error[E0597]: `i` does not live long enough
146+
エラー[E0597]: `i`は十分なライフタイムを持っていません
131147
--> src/lib.rs:15:15
132148
|
133149
15 | print_it(&i);
134150
| ---------^^--
135151
| | |
136152
| | borrowed value does not live long enough
153+
| | 借用した値のライフタイムが不足
137154
| argument requires that `i` is borrowed for `'static`
155+
| 引数は`i`が`'static`として借用されることを要求する
138156
16 | }
139157
| - `i` dropped here while still borrowed
158+
| `i`は借用されたままここでドロップされる
140159
```
141160

142161
<!--

0 commit comments

Comments
 (0)