Skip to content

Commit 72a6288

Browse files
authored
Merge pull request #182 from todays-mitsui/translate-static_lifetime
Translate untranslated lines in static_lifetime.md
2 parents 9b5c9ee + ad0b6ce commit 72a6288

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

src/scope/lifetime/static_lifetime.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,39 @@ let s: &'static str = "hello world";
1717
fn generic<T>(x: T) where T: 'static {}
1818
```
1919

20+
<!--
2021
Both are related but subtly different and this is a common source for
2122
confusion when learning Rust. Here are some examples for each situation:
23+
-->
24+
2つの状況における`static`は微妙に異なる意味を持っており、Rustを学ぶときの混乱の元になっています。
25+
いくつかの例とともにそれぞれの使い方を見てみましょう。
2226

27+
<!--
2328
## Reference lifetime
29+
-->
30+
## 参照のライフタイム
2431

32+
<!--
2533
As a reference lifetime `'static` indicates that the data pointed to by
2634
the reference lives for the entire lifetime of the running program.
2735
It can still be coerced to a shorter lifetime.
36+
-->
37+
参照のライフタイムが`'static`であることは、参照が指し示す値がプログラムの実行中に渡って生き続けることを示します。
38+
また、より短いライフタイムに圧縮することも可能です。
2839

40+
<!--
2941
There are two ways to make a variable with `'static` lifetime, and both
3042
are stored in the read-only memory of the binary:
43+
-->
44+
`'static`ライフタイムを持つ変数を作るには下記の2つ方法があります。
45+
どちらの場合も、値は読み取り専用のメモリ領域に格納されます。
3146

3247
<!--
3348
* Make a constant with the `static` declaration.
3449
* Make a `string` literal which has type: `&'static str`.
3550
-->
3651
* `static`宣言とともに定数を作成する。
37-
* 文字列リテラル で`&'static str`型を持つ変数を作成する。
52+
* 文字列リテラルで`&'static str`型を持つ変数を作成する。
3853

3954
<!--
4055
See the following example for a display of each method:
@@ -83,15 +98,25 @@ fn main() {
8398
}
8499
```
85100

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

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

114+
<!--
92115
It's important to understand this means that any owned data always passes
93116
a `'static` lifetime bound, but a reference to that owned data generally
94117
does not:
118+
-->
119+
次のポイントを押さえておきましょう。所有権のある値が`'static`ライフタイム境界をパスするとしても、その値への参照が`'static`ライフタイム境界をパスするとは限りません。
95120

96121
```rust,editable,compile_fail
97122
use std::fmt::Debug;
@@ -102,26 +127,35 @@ fn print_it( input: impl Debug + 'static ) {
102127
103128
fn main() {
104129
// i is owned and contains no references, thus it's 'static:
130+
// i は所有されていて、かつ参照を含まないので 'static
105131
let i = 5;
106132
print_it(i);
107133
108134
// oops, &i only has the lifetime defined by the scope of
109135
// main(), so it's not 'static:
136+
// おっと、&i は main() で定義されたライフタイムしかもたないため 'static ではない
110137
print_it(&i);
111138
}
112139
```
140+
<!--
113141
The compiler will tell you:
142+
-->
143+
コンパイラのメッセージはこのようになります、
114144
```ignore
115145
error[E0597]: `i` does not live long enough
146+
エラー[E0597]: `i`は十分なライフタイムを持っていません
116147
--> src/lib.rs:15:15
117148
|
118149
15 | print_it(&i);
119150
| ---------^^--
120151
| | |
121152
| | borrowed value does not live long enough
153+
| | 借用した値のライフタイムが不足
122154
| argument requires that `i` is borrowed for `'static`
155+
| 引数は`i`が`'static`として借用されることを要求する
123156
16 | }
124157
| - `i` dropped here while still borrowed
158+
| `i`は借用されたままここでドロップされる
125159
```
126160

127161
<!--

0 commit comments

Comments
 (0)