Skip to content

Commit 8942ab0

Browse files
committed
ci: generate pages at 368c34d [ci skip]
1 parent 368c34d commit 8942ab0

File tree

8 files changed

+172
-52
lines changed

8 files changed

+172
-52
lines changed

docs/fn/closures/capture.html

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,13 @@ <h1 id="要素の捕捉"><a class="header" href="#要素の捕捉">要素の捕
197197

198198
// `color` can be borrowed immutably again, because the closure only holds
199199
// an immutable reference to `color`.
200+
// `color`を再びイミュータブルで借用することができる。
201+
// これはクロージャが`color`に対するイミュータブルな参照しか保持しないからである。
200202
let _reborrow = &amp;color;
201203
print();
202204

203205
// A move or reborrow is allowed after the final use of `print`
206+
// 最後に`print`を使用した後は移動や再借用が許可される。
204207
let _color_moved = color;
205208

206209

@@ -230,16 +233,23 @@ <h1 id="要素の捕捉"><a class="header" href="#要素の捕捉">要素の捕
230233

231234
// The closure still mutably borrows `count` because it is called later.
232235
// An attempt to reborrow will lead to an error.
236+
// クロージャはまだ `count` をミュータブルで借用している。
237+
// なぜなら後で呼ばれるからである。
238+
// 再借用しようとするとエラーになる。
233239
// let _reborrow = &amp;count;
234240
// ^ TODO: try uncommenting this line.
241+
// ^ TODO: この行のコメントアウトを解除しましょう。
235242
inc();
236243

237244
// The closure no longer needs to borrow `&amp;mut count`. Therefore, it is
238245
// possible to reborrow without an error
246+
// クロージャはもう`&amp;mut count`を借用する必要がない。
247+
// なので、エラーを起こさず再借用することができる。
239248
let _count_reborrowed = &amp;mut count;
240249

241250

242251
// A non-copy type.
252+
// コピー不可能な型
243253
let movable = Box::new(3);
244254

245255
// `mem::drop` requires `T` so this must take by value. A copy type
@@ -262,10 +272,14 @@ <h1 id="要素の捕捉"><a class="header" href="#要素の捕捉">要素の捕
262272
// ^ TODO: この行のコメントアウトを解除しましょう。
263273
}
264274
</code></pre></pre>
265-
<p>Using <code>move</code> before vertical pipes forces closure
266-
to take ownership of captured variables:</p>
275+
<!--
276+
Using `move` before vertical pipes forces closure
277+
to take ownership of captured variables:
278+
-->
279+
<p>バーティカルパイプ(訳注:縦線記号<code>||</code>)の前に<code>move</code>を使用することで、キャプチャする変数の所有権を取ることをクロージャに強制します。</p>
267280
<pre><pre class="playground"><code class="language-rust editable">fn main() {
268281
// `Vec` has non-copy semantics.
282+
// `Vec`はコピーセマンティクスではない。
269283
let haystack = vec![1, 2, 3];
270284

271285
let contains = move |needle| haystack.contains(needle);
@@ -277,10 +291,16 @@ <h1 id="要素の捕捉"><a class="header" href="#要素の捕捉">要素の捕
277291
// ^ Uncommenting above line will result in compile-time error
278292
// because borrow checker doesn't allow re-using variable after it
279293
// has been moved.
294+
// ^ 上の行のコメントアウトを解除すると、コンパイル時エラーになる。
295+
// これは変数の所有権が移された後の再利用を借用チェッカーが許可しないからである。
280296

281297
// Removing `move` from closure's signature will cause closure
282298
// to borrow _haystack_ variable immutably, hence _haystack_ is still
283299
// available and uncommenting above line will not cause an error.
300+
// クロージャのシグネチャから`move`を削除すると、クロージャは _haystack_ 変数を
301+
// イミュータブルで借用するようになる。
302+
// そのため _haystack_ はまだ利用可能となり、上の行のコメントアウトを解除しても
303+
// エラーが発生しなくなる。
284304
}
285305
</code></pre></pre>
286306
<!--

docs/fn/closures/closure_examples/iter_find.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,12 @@ <h1 id="searching-through-iterators"><a class="header" href="#searching-through-
203203
println!(&quot;Find 2 in array2: {:?}&quot;, array2.into_iter().find(|&amp;&amp;x| x == 2));
204204
}
205205
</code></pre></pre>
206-
<p><code>Iterator::find</code> gives you a reference to the item. But if you want the <em>index</em> of the
207-
item, use <code>Iterator::position</code>.</p>
206+
<!--
207+
`Iterator::find` gives you a reference to the item. But if you want the _index_ of the
208+
item, use `Iterator::position`.
209+
-->
210+
<p><code>Iterator::find</code>は要素への参照を返します。
211+
要素の <em>インデックス</em> を使用したい場合、<code>Iterator::position</code>を使用してください。</p>
208212
<pre><pre class="playground"><code class="language-rust editable">fn main() {
209213
let vec = vec![1, 9, 3, 3, 13, 2];
210214

docs/fn/closures/input_functions.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,14 @@ <h1 id="関数を受け取る関数"><a class="header" href="#関数を受け取
167167
}
168168

169169
// Define a wrapper function satisfying the `Fn` bound
170+
// `Fn`境界を満たすラッパ関数を定義
170171
fn function() {
171172
println!(&quot;I'm a function!&quot;);
172173
}
173174

174175
fn main() {
175176
// Define a closure satisfying the `Fn` bound
177+
// `Fn`境界を満たすクロージャを定義
176178
let closure = || println!(&quot;I'm a closure!&quot;);
177179

178180
call_me(closure);

docs/fn/closures/input_parameters.html

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -150,28 +150,52 @@ <h1 class="menu-title">Rust By Example 日本語版</h1>
150150
# As input parameters
151151
-->
152152
<h1 id="捕捉時の型推論"><a class="header" href="#捕捉時の型推論">捕捉時の型推論</a></h1>
153-
<p>While Rust chooses how to capture variables on the fly mostly without type
153+
<!--
154+
While Rust chooses how to capture variables on the fly mostly without type
154155
annotation, this ambiguity is not allowed when writing functions. When
155156
taking a closure as an input parameter, the closure's complete type must be
156-
annotated using one of a few <code>traits</code>. In order of decreasing restriction,
157-
they are:</p>
157+
annotated using one of a few `traits`. In order of decreasing restriction,
158+
they are:
159+
-->
160+
<p>Rustはたいていの場合、型アノテーションなしでも変数を捕捉する方法を臨機応変に選択してくれますが、関数を書く場合にはこの曖昧さは許されません。
161+
引数のパラメータとしてクロージャを取る場合、そのクロージャの完全な型はいくつかの<code>traits</code>の中の1つを使って明示されなければなりません。
162+
制限の少ない順に並べると、下記の通りです。</p>
163+
<!--
164+
* `Fn`: the closure captures by reference (`&T`)
165+
* `FnMut`: the closure captures by mutable reference (`&mut T`)
166+
* `FnOnce`: the closure captures by value (`T`)
167+
-->
158168
<ul>
159-
<li><code>Fn</code>: the closure captures by reference (<code>&amp;T</code>)</li>
160-
<li><code>FnMut</code>: the closure captures by mutable reference (<code>&amp;mut T</code>)</li>
161-
<li><code>FnOnce</code>: the closure captures by value (<code>T</code>)</li>
169+
<li><code>Fn</code>: 参照(<code>&amp;T</code>)によって捕捉するクロージャ</li>
170+
<li><code>FnMut</code>: ミュータブルな参照(<code>&amp;mut T</code>)によって捕捉するクロージャ</li>
171+
<li><code>FnOnce</code>: (<code>T</code>)によって捕捉するクロージャ</li>
162172
</ul>
163-
<p>On a variable-by-variable basis, the compiler will capture variables in the
164-
least restrictive manner possible.</p>
165-
<p>For instance, consider a parameter annotated as <code>FnOnce</code>. This specifies
166-
that the closure <em>may</em> capture by <code>&amp;T</code>, <code>&amp;mut T</code>, or <code>T</code>, but the compiler
173+
<!--
174+
On a variable-by-variable basis, the compiler will capture variables in the
175+
least restrictive manner possible.
176+
-->
177+
<p>変数ごとに、コンパイラは可能な限り制約の少ない方法でその変数を捕捉します。</p>
178+
<!--
179+
For instance, consider a parameter annotated as `FnOnce`. This specifies
180+
that the closure *may* capture by `&T`, `&mut T`, or `T`, but the compiler
167181
will ultimately choose based on how the captured variables are used in the
168-
closure.</p>
169-
<p>This is because if a move is possible, then any type of borrow should also
182+
closure.
183+
-->
184+
<p>例えば、<code>FnOnce</code>というアノテーションの付けられたパラメータを考えてみましょう。
185+
これはそのクロージャが<code>&amp;T</code><code>&amp;mut T</code>もしくは<code>T</code><em>どれか</em> で捕捉することを指定するものですが、コンパイラは捕捉した変数がそのクロージャの中でどのように使用されるかに基づき、最終的に捕捉する方法を選択することになります。</p>
186+
<!--
187+
This is because if a move is possible, then any type of borrow should also
170188
be possible. Note that the reverse is not true. If the parameter is
171-
annotated as <code>Fn</code>, then capturing variables by <code>&amp;mut T</code> or <code>T</code> are not
172-
allowed.</p>
173-
<p>In the following example, try swapping the usage of <code>Fn</code>, <code>FnMut</code>, and
174-
<code>FnOnce</code> to see what happens:</p>
189+
annotated as `Fn`, then capturing variables by `&mut T` or `T` are not
190+
allowed.
191+
-->
192+
<p>これは、もし移動が可能であれば、いずれの種類の借用であっても同様に可能だからです。
193+
その逆は正しくないことに注意してください。パラメータが<code>Fn</code>としてアノテーションされている場合、変数を<code>&amp;mut T</code><code>T</code>で捕捉することは許可されません。</p>
194+
<!--
195+
In the following example, try swapping the usage of `Fn`, `FnMut`, and
196+
`FnOnce` to see what happens:
197+
-->
198+
<p>以下の例では、<code>Fn</code><code>FnMut</code>、および<code>FnOnce</code>を入れ替えて、何が起こるのかを見てみましょう。</p>
175199
<pre><pre class="playground"><code class="language-rust editable">// A function which takes a closure as an argument and calls it.
176200
// &lt;F&gt; denotes that F is a &quot;Generic type parameter&quot;
177201
fn apply&lt;F&gt;(f: F) where

docs/fn/closures/output_parameters.html

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,20 +150,30 @@ <h1 class="menu-title">Rust By Example 日本語版</h1>
150150
# As output parameters
151151
-->
152152
<h1 id="クロージャを返す関数"><a class="header" href="#クロージャを返す関数">クロージャを返す関数</a></h1>
153-
<p>Closures as input parameters are possible, so returning closures as
153+
<!--
154+
Closures as input parameters are possible, so returning closures as
154155
output parameters should also be possible. However, anonymous
155156
closure types are, by definition, unknown, so we have to use
156-
<code>impl Trait</code> to return them.</p>
157-
<p>The valid traits for returning a closure are:</p>
157+
`impl Trait` to return them.
158+
-->
159+
<p>クロージャを引数のパラメータとして用いることができるのと同様に、クロージャを戻り値として返すことも可能です。しかし無名のクロージャの型はその定義上、不明であるため、クロージャを返すためには<code>impl Trait</code>を使用する必要があります。</p>
160+
<!--
161+
The valid traits for returning a closure are:
162+
-->
163+
<p>クロージャを返すために有効なトレイトは下記の通りです。</p>
158164
<ul>
159165
<li><code>Fn</code></li>
160166
<li><code>FnMut</code></li>
161167
<li><code>FnOnce</code></li>
162168
</ul>
163-
<p>Beyond this, the <code>move</code> keyword must be used, which signals that all captures
169+
<!--
170+
Beyond this, the `move` keyword must be used, which signals that all captures
164171
occur by value. This is required because any captures by reference would be
165172
dropped as soon as the function exited, leaving invalid references in the
166-
closure.</p>
173+
closure.
174+
-->
175+
<p>更に、<code>move</code>というキーワードを使用し、全ての捕捉が値でおこなわれることを明示しなければなりません。
176+
これは、関数を抜けると同時に参照による捕捉がドロップされ、無効な参照がクロージャに残ってしまうのを防ぐためです。</p>
167177
<pre><pre class="playground"><code class="language-rust editable">fn create_fn() -&gt; impl Fn() {
168178
let text = &quot;Fn&quot;.to_owned();
169179

0 commit comments

Comments
 (0)