Skip to content

Commit ccafb9c

Browse files
committed
generate
1 parent 1b8ed27 commit ccafb9c

File tree

2 files changed

+102
-40
lines changed

2 files changed

+102
-40
lines changed

public/1.6/book/borrow-and-asref.html

Lines changed: 77 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="utf-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66
<meta name="generator" content="rustdoc">
7-
<title>Borrow and AsRef</title>
7+
<title>BorrowとAsRef</title>
88

99
<link rel="stylesheet" type="text/css" href="rustbook.css">
1010

@@ -185,15 +185,27 @@
185185
<div id='page'>
186186

187187

188-
<h1 class="title">Borrow and AsRef</h1>
189-
<p>The <a href="../std/borrow/trait.Borrow.html"><code>Borrow</code></a> and <a href="../std/convert/trait.AsRef.html"><code>AsRef</code></a> traits are very similar, but
190-
different. Here’s a quick refresher on what these two traits mean.</p>
188+
<h1 class="title">BorrowとAsRef</h1>
189+
<!-- % Borrow and AsRef -->
190+
191+
<!-- The [`Borrow`][borrow] and [`AsRef`][asref] traits are very similar, but -->
192+
193+
<!-- different. Here’s a quick refresher on what these two traits mean. -->
194+
195+
<p><a href="../std/borrow/trait.Borrow.html"><code>Borrow</code></a> トレイトと <a href="../std/convert/trait.AsRef.html"><code>AsRef</code></a> トレイトはとてもよく似ていますが違うものです。ここでは2つのトレイトの意味を簡単に説明します。</p>
196+
197+
<!-- # Borrow -->
191198

192199
<h1 id='borrow' class='section-header'><a href='#borrow'>Borrow</a></h1>
193-
<p>The <code>Borrow</code> trait is used when you’re writing a datastructure, and you want to
194-
use either an owned or borrowed type as synonymous for some purpose.</p>
200+
<!-- The `Borrow` trait is used when you’re writing a datastructure, and you want to -->
195201

196-
<p>For example, <a href="../std/collections/struct.HashMap.html"><code>HashMap</code></a> has a <a href="../std/collections/struct.HashMap.html#method.get"><code>get</code> method</a> which uses <code>Borrow</code>:</p>
202+
<!-- use either an owned or borrowed type as synonymous for some purpose. -->
203+
204+
<p><code>Borrow</code> トレイトはデータ構造を書いていて、所有型と借用型を同等に扱いたいときに使います。</p>
205+
206+
<!-- For example, [`HashMap`][hashmap] has a [`get` method][get] which uses `Borrow`: -->
207+
208+
<p>例えば、 <a href="../std/collections/struct.HashMap.html"><code>HashMap</code></a> には <code>Borrow</code> を使った <a href="../std/collections/struct.HashMap.html#method.get"><code>get</code> メソッド</a> があります。</p>
197209
<span class='rusttest'>fn main() {
198210
fn get&lt;Q: ?Sized&gt;(&amp;self, k: &amp;Q) -&gt; Option&lt;&amp;V&gt;
199211
where K: Borrow&lt;Q&gt;,
@@ -203,17 +215,25 @@ <h1 id='borrow' class='section-header'><a href='#borrow'>Borrow</a></h1>
203215
<span class='kw'>where</span> <span class='ident'>K</span>: <span class='ident'>Borrow</span><span class='op'>&lt;</span><span class='ident'>Q</span><span class='op'>&gt;</span>,
204216
<span class='ident'>Q</span>: <span class='ident'>Hash</span> <span class='op'>+</span> <span class='ident'>Eq</span></pre>
205217

206-
<p>This signature is pretty complicated. The <code>K</code> parameter is what we’re interested
207-
in here. It refers to a parameter of the <code>HashMap</code> itself:</p>
218+
<!-- This signature is pretty complicated. The `K` parameter is what we’re interested -->
219+
220+
<!-- in here. It refers to a parameter of the `HashMap` itself: -->
221+
222+
<p>このシグネチャは少し複雑です。<code>K</code> パラメータに注目してください。これは以下のように <code>HashMap</code> 自身のパラメータになっています。</p>
208223
<span class='rusttest'>fn main() {
209224
struct HashMap&lt;K, V, S = RandomState&gt; {
210225
}</span><pre class='rust rust-example-rendered'>
211226
<span class='kw'>struct</span> <span class='ident'>HashMap</span><span class='op'>&lt;</span><span class='ident'>K</span>, <span class='ident'>V</span>, <span class='ident'>S</span> <span class='op'>=</span> <span class='ident'>RandomState</span><span class='op'>&gt;</span> {</pre>
212227

213-
<p>The <code>K</code> parameter is the type of <em>key</em> the <code>HashMap</code> uses. So, looking at
214-
the signature of <code>get()</code> again, we can use <code>get()</code> when the key implements
215-
<code>Borrow&lt;Q&gt;</code>. That way, we can make a <code>HashMap</code> which uses <code>String</code> keys,
216-
but use <code>&amp;str</code>s when we’re searching:</p>
228+
<!-- The `K` parameter is the type of _key_ the `HashMap` uses. So, looking at -->
229+
230+
<!-- the signature of `get()` again, we can use `get()` when the key implements -->
231+
232+
<!-- `Borrow<Q>`. That way, we can make a `HashMap` which uses `String` keys, -->
233+
234+
<!-- but use `&str`s when we’re searching: -->
235+
236+
<p><code>K</code> パラメータは <code>HashMap</code> の「キー」を表す型です。ここで再び <code>get()</code> のシグネチャを見ると、キーが <code>Borrow&lt;Q&gt;</code> を実装しているときに <code>get()</code> を使えることが分かります。そのため、以下のように <code>String</code> をキーとした <code>HashMap</code> を検索するときに <code>&amp;str</code> を使うことができます。</p>
217237
<span class='rusttest'>fn main() {
218238
use std::collections::HashMap;
219239

@@ -229,13 +249,21 @@ <h1 id='borrow' class='section-header'><a href='#borrow'>Borrow</a></h1>
229249

230250
<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>map</span>.<span class='ident'>get</span>(<span class='string'>&quot;Foo&quot;</span>), <span class='prelude-val'>Some</span>(<span class='kw-2'>&amp;</span><span class='number'>42</span>));</pre>
231251

232-
<p>This is because the standard library has <code>impl Borrow&lt;str&gt; for String</code>.</p>
252+
<!-- This is because the standard library has `impl Borrow<str> for String`. -->
253+
254+
<p>これは標準ライブラリが <code>impl Borrow&lt;str&gt; for String</code> を提供しているためです。</p>
255+
256+
<!-- For most types, when you want to take an owned or borrowed type, a `&T` is -->
257+
258+
<!-- enough. But one area where `Borrow` is effective is when there’s more than one -->
233259

234-
<p>For most types, when you want to take an owned or borrowed type, a <code>&amp;T</code> is
235-
enough. But one area where <code>Borrow</code> is effective is when there’s more than one
236-
kind of borrowed value. This is especially true of references and slices: you
237-
can have both an <code>&amp;T</code> or a <code>&amp;mut T</code>. If we wanted to accept both of these types,
238-
<code>Borrow</code> is up for it:</p>
260+
<!-- kind of borrowed value. This is especially true of references and slices: you -->
261+
262+
<!-- can have both an `&T` or a `&mut T`. If we wanted to accept both of these types, -->
263+
264+
<!-- `Borrow` is up for it: -->
265+
266+
<p>所有型か借用型のどちらかを取りたい場合、たいていは <code>&amp;T</code> で十分ですが、借用された値が複数種類ある場合 <code>Borrow</code> が役に立ちます。特に参照とスライスは <code>&amp;T</code><code>&amp;mut T</code> のいずれも取りうるため、そのどちらも受け入れたい場合は <code>Borrow</code> がよいでしょう。</p>
239267
<span class='rusttest'>fn main() {
240268
use std::borrow::Borrow;
241269
use std::fmt::Display;
@@ -261,11 +289,18 @@ <h1 id='borrow' class='section-header'><a href='#borrow'>Borrow</a></h1>
261289
<span class='ident'>foo</span>(<span class='kw-2'>&amp;</span><span class='ident'>i</span>);
262290
<span class='ident'>foo</span>(<span class='kw-2'>&amp;</span><span class='kw-2'>mut</span> <span class='ident'>i</span>);</pre>
263291

264-
<p>This will print out <code>a is borrowed: 5</code> twice.</p>
292+
<!-- This will print out `a is borrowed: 5` twice. -->
293+
294+
<p>上のコードは <code>a is borrowed: 5</code> を二度出力します。</p>
295+
296+
<!-- # AsRef -->
265297

266298
<h1 id='asref' class='section-header'><a href='#asref'>AsRef</a></h1>
267-
<p>The <code>AsRef</code> trait is a conversion trait. It’s used for converting some value to
268-
a reference in generic code. Like this:</p>
299+
<!-- The `AsRef` trait is a conversion trait. It’s used for converting some value to -->
300+
301+
<!-- a reference in generic code. Like this: -->
302+
303+
<p><code>AsRef</code> トレイトは変換用のトレイトです。ジェネリックなコードにおいて、値を参照に変換したい場合に使います。</p>
269304
<span class='rusttest'>fn main() {
270305
let s = &quot;Hello&quot;.to_string();
271306

@@ -279,16 +314,28 @@ <h1 id='asref' class='section-header'><a href='#asref'>AsRef</a></h1>
279314
<span class='kw'>let</span> <span class='ident'>slice</span> <span class='op'>=</span> <span class='ident'>s</span>.<span class='ident'>as_ref</span>();
280315
}</pre>
281316

282-
<h1 id='which-should-i-use' class='section-header'><a href='#which-should-i-use'>Which should I use?</a></h1>
283-
<p>We can see how they’re kind of the same: they both deal with owned and borrowed
284-
versions of some type. However, they’re a bit different.</p>
317+
<!-- # Which should I use? -->
318+
319+
<h1 id='どちらを使うべきか' class='section-header'><a href='#どちらを使うべきか'>どちらを使うべきか</a></h1>
320+
<!-- We can see how they’re kind of the same: they both deal with owned and borrowed -->
321+
322+
<!-- versions of some type. However, they’re a bit different. -->
323+
324+
<p>ここまでで見てきた通り、2つのトレイトは、どちらもある型の所有型バージョンと借用型バージョンの両方を扱う、という意味で同じような種類のものですが、少し違います。</p>
325+
326+
<!-- Choose `Borrow` when you want to abstract over different kinds of borrowing, or -->
327+
328+
<!-- when you’re building a datastructure that treats owned and borrowed values in -->
329+
330+
<!-- equivalent ways, such as hashing and comparison. -->
331+
332+
<p>いくつかの異なる種類の借用を抽象化したい場合や、ハッシュ化や比較のために所有型と借用型を同等に扱いたいデータ構造を作る場合は <code>Borrow</code> を使ってください。</p>
333+
334+
<!-- Choose `AsRef` when you want to convert something to a reference directly, and -->
285335

286-
<p>Choose <code>Borrow</code> when you want to abstract over different kinds of borrowing, or
287-
when you’re building a datastructure that treats owned and borrowed values in
288-
equivalent ways, such as hashing and comparison.</p>
336+
<!-- you’re writing generic code. -->
289337

290-
<p>Choose <code>AsRef</code> when you want to convert something to a reference directly, and
291-
you’re writing generic code.</p>
338+
<p>ジェネリックなコードで値を参照に直接変換したい場合は <code>AsRef</code> を使ってください。</p>
292339

293340
<script type="text/javascript">
294341
window.playgroundUrl = "https://play.rust-lang.org";

public/1.6/book/intrinsics.html

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,30 @@
186186

187187

188188
<h1 class="title">Intrinsics</h1>
189-
<blockquote>
190-
<p><strong>Note</strong>: intrinsics will forever have an unstable interface, it is
191-
recommended to use the stable interfaces of libcore rather than intrinsics
192-
directly.</p>
189+
<!-- > **Note**: intrinsics will forever have an unstable interface, it is -->
190+
191+
<!-- > recommended to use the stable interfaces of libcore rather than intrinsics -->
192+
193+
<!-- > directly. -->
194+
195+
<blockquote>
196+
<p><strong>メモ</strong>: intrinsicsのインタフェースは常に不安定です、intrinsicsを直接利用するのではなく、
197+
libcoreの安定なインタフェースを利用することを推奨します。</p>
193198
</blockquote>
194199

195-
<p>These are imported as if they were FFI functions, with the special
196-
<code>rust-intrinsic</code> ABI. For example, if one was in a freestanding
197-
context, but wished to be able to <code>transmute</code> between types, and
198-
perform efficient pointer arithmetic, one would import those functions
199-
via a declaration like</p>
200+
<!-- These are imported as if they were FFI functions, with the special -->
201+
202+
<!-- `rust-intrinsic` ABI. For example, if one was in a freestanding -->
203+
204+
<!-- context, but wished to be able to `transmute` between types, and -->
205+
206+
<!-- perform efficient pointer arithmetic, one would import those functions -->
207+
208+
<!-- via a declaration like -->
209+
210+
<p>intrinsicsは特別なABI <code>rust-intrinsic</code> を用いて、FFIの関数で有るかのようにインポートされます。
211+
例えば、独立したコンテキストの中で型の間の <code>transmute</code> をしたい場合や、効率的なポインタ演算を行いたい場合、
212+
それらの関数を以下のような宣言を通してインポートします</p>
200213
<span class='rusttest'>#![feature(intrinsics)]
201214
fn main() {}
202215

@@ -214,7 +227,9 @@ <h1 class="title">Intrinsics</h1>
214227
<span class='kw'>fn</span> <span class='ident'>offset</span><span class='op'>&lt;</span><span class='ident'>T</span><span class='op'>&gt;</span>(<span class='ident'>dst</span>: <span class='op'>*</span><span class='kw'>const</span> <span class='ident'>T</span>, <span class='ident'>offset</span>: <span class='ident'>isize</span>) <span class='op'>-&gt;</span> <span class='op'>*</span><span class='kw'>const</span> <span class='ident'>T</span>;
215228
}</pre>
216229

217-
<p>As with any other FFI functions, these are always <code>unsafe</code> to call.</p>
230+
<!-- As with any other FFI functions, these are always `unsafe` to call. -->
231+
232+
<p>他のFFI関数と同様に、呼出は常に <code>unsafe</code> です。</p>
218233

219234
<script type="text/javascript">
220235
window.playgroundUrl = "https://play.rust-lang.org";

0 commit comments

Comments
 (0)