@@ -22,7 +22,7 @@ Both are related but subtly different and this is a common source for
22
22
confusion when learning Rust. Here are some examples for each situation:
23
23
-->
24
24
2つの状況における` static ` は微妙に異なる意味を持っており、Rustを学ぶときの混乱の元になっています。
25
- いくつかの例とともにそれぞれの状況について見てみましょう 。
25
+ いくつかの例とともにそれぞれの使い方を見てみましょう 。
26
26
27
27
<!--
28
28
## Reference lifetime
@@ -35,7 +35,7 @@ the reference lives for the entire lifetime of the running program.
35
35
It can still be coerced to a shorter lifetime.
36
36
-->
37
37
参照のライフタイムが` 'static ` であることは、参照が指し示すデータがプログラムの実行中に渡って生き続けることを示します。
38
- また、より短いライフタイムに強制することも可能です 。
38
+ また、より短いライフタイムに圧縮することも可能です 。
39
39
40
40
<!--
41
41
There are two ways to make a variable with `'static` lifetime, and both
@@ -98,15 +98,25 @@ fn main() {
98
98
}
99
99
```
100
100
101
+ <!--
101
102
## Trait bound
103
+ -->
104
+ ## トレイト境界
102
105
106
+ <!--
103
107
As a trait bound, it means the type does not contain any non-static
104
108
references. Eg. the receiver can hold on to the type for as long as
105
109
they want and it will never become invalid until they drop it.
110
+ -->
111
+ トレイト境界としての` 'static ` は型が非静的な参照を含まないことを意味します。
112
+ 言い換えると、レシーバはその型をいくらでも長く保持することができ、意図的にドロップするまでは決して無効になることはないということです。
106
113
114
+ <!--
107
115
It's important to understand this means that any owned data always passes
108
116
a `'static` lifetime bound, but a reference to that owned data generally
109
117
does not:
118
+ -->
119
+ ここで注意しなければいけないのは、所有権のあるデータが` 'static ` ライフタイム境界をパスするとしても、そのデータへの参照は` 'static ` ライフタイム境界をパスしないということです。
110
120
111
121
``` rust,editable,compile_fail
112
122
use std::fmt::Debug;
@@ -117,26 +127,35 @@ fn print_it( input: impl Debug + 'static ) {
117
127
118
128
fn main() {
119
129
// i is owned and contains no references, thus it's 'static:
130
+ // i は所有されていて、かつ参照を含まないので 'static
120
131
let i = 5;
121
132
print_it(i);
122
133
123
134
// oops, &i only has the lifetime defined by the scope of
124
135
// main(), so it's not 'static:
136
+ // おっと、&i は main() で定義されたライフタイムしかもたないため 'static ではない
125
137
print_it(&i);
126
138
}
127
139
```
140
+ <!--
128
141
The compiler will tell you:
142
+ -->
143
+ コンパイラのメッセージはこのようになります、
129
144
``` ignore
130
145
error[E0597]: `i` does not live long enough
146
+ エラー[E0597]: `i`は十分なライフタイムを持っていません
131
147
--> src/lib.rs:15:15
132
148
|
133
149
15 | print_it(&i);
134
150
| ---------^^--
135
151
| | |
136
152
| | borrowed value does not live long enough
153
+ | | 借用した値のライフタイムが不足
137
154
| argument requires that `i` is borrowed for `'static`
155
+ | 引数は`i`が`'static`として借用されることを要求する
138
156
16 | }
139
157
| - `i` dropped here while still borrowed
158
+ | `i`は借用されたままここでドロップされる
140
159
```
141
160
142
161
<!--
0 commit comments