Skip to content

Commit 361f41a

Browse files
committed
generate
1 parent a7036cd commit 361f41a

File tree

1 file changed

+65
-25
lines changed

1 file changed

+65
-25
lines changed

public/1.6/book/ufcs.html

Lines changed: 65 additions & 25 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>Universal Function Call Syntax</title>
7+
<title>共通の関数呼び出し構文</title>
88

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

@@ -185,8 +185,12 @@
185185
<div id='page'>
186186

187187

188-
<h1 class="title">Universal Function Call Syntax</h1>
189-
<p>Sometimes, functions can have the same names. Consider this code:</p>
188+
<h1 class="title">共通の関数呼び出し構文</h1>
189+
<!-- % Universal Function Call Syntax -->
190+
191+
<!-- Sometimes, functions can have the same names. Consider this code: -->
192+
193+
<p>しばしば、同名の関数が存在する時があります。たとえば、以下のコードでは:</p>
190194
<span class='rusttest'>fn main() {
191195
trait Foo {
192196
fn f(&amp;self);
@@ -228,7 +232,9 @@ <h1 class="title">Universal Function Call Syntax</h1>
228232

229233
<span class='kw'>let</span> <span class='ident'>b</span> <span class='op'>=</span> <span class='ident'>Baz</span>;</pre>
230234

231-
<p>If we were to try to call <code>b.f()</code>, we’d get an error:</p>
235+
<!-- If we were to try to call `b.f()`, we’d get an error: -->
236+
237+
<p>もしここで、 <code>b.f()</code> を呼びだそうとすると、以下の様なエラーが発生します:</p>
232238

233239
<pre><code class="language-text">error: multiple applicable methods in scope [E0034]
234240
b.f();
@@ -244,8 +250,12 @@ <h1 class="title">Universal Function Call Syntax</h1>
244250

245251
</code></pre>
246252

247-
<p>We need a way to disambiguate which method we need. This feature is called
248-
‘universal function call syntax’, and it looks like this:</p>
253+
<!-- We need a way to disambiguate which method we need. This feature is called -->
254+
255+
<!-- ‘universal function call syntax’, and it looks like this: -->
256+
257+
<p>このような場合は、どのメソッドを呼び出す必要があるのかについて曖昧性を排除する手段が必要です。
258+
そのようなフィーチャーは 「共通の関数呼び出し構文」と呼ばれ、以下のように書けます:</p>
249259
<span class='rusttest'>fn main() {
250260
trait Foo {
251261
fn f(&amp;self);
@@ -267,47 +277,74 @@ <h1 class="title">Universal Function Call Syntax</h1>
267277
<span class='ident'>Foo</span>::<span class='ident'>f</span>(<span class='kw-2'>&amp;</span><span class='ident'>b</span>);
268278
<span class='ident'>Bar</span>::<span class='ident'>f</span>(<span class='kw-2'>&amp;</span><span class='ident'>b</span>);</pre>
269279

270-
<p>Let’s break it down.</p>
280+
<!-- Let’s break it down. -->
281+
282+
<p>部分的に見ていきましょう。</p>
271283
<span class='rusttest'>fn main() {
272284
Foo::
273285
Bar::
274286
}</span><pre class='rust rust-example-rendered'>
275287
<span class='ident'>Foo</span>::
276288
<span class='ident'>Bar</span>::</pre>
277289

278-
<p>These halves of the invocation are the types of the two traits: <code>Foo</code> and
279-
<code>Bar</code>. This is what ends up actually doing the disambiguation between the two:
280-
Rust calls the one from the trait name you use.</p>
290+
<!-- These halves of the invocation are the types of the two traits: `Foo` and -->
291+
292+
<!-- `Bar`. This is what ends up actually doing the disambiguation between the two: -->
293+
294+
<!-- Rust calls the one from the trait name you use. -->
295+
296+
<p>まず、呼び出しのこの部分は2つのトレイト <code>Foo</code><code>Bar</code> の型を表しています。
297+
この部分が、実際にどちらのトレイトのメソッドを呼び出しているのかを指定し、曖昧性を排除している箇所になります。</p>
281298
<span class='rusttest'>fn main() {
282299
f(&amp;b)
283300
}</span><pre class='rust rust-example-rendered'>
284301
<span class='ident'>f</span>(<span class='kw-2'>&amp;</span><span class='ident'>b</span>)</pre>
285302

286-
<p>When we call a method like <code>b.f()</code> using <a href="method-syntax.html">method syntax</a>, Rust
287-
will automatically borrow <code>b</code> if <code>f()</code> takes <code>&amp;self</code>. In this case, Rust will
288-
not, and so we need to pass an explicit <code>&amp;b</code>.</p>
303+
<!-- When we call a method like `b.f()` using [method syntax][methodsyntax], Rust -->
304+
305+
<!-- will automatically borrow `b` if `f()` takes `&self`. In this case, Rust will -->
306+
307+
<!-- not, and so we need to pass an explicit `&b`. -->
308+
309+
<p><code>b.f()</code> のように <a href="method-syntax.html">メソッド構文</a> を利用して呼び出した時、Rustは <code>f()</code><code>&amp;self</code> を引数に取る場合自動的に <code>b</code> を借用します。
310+
今回の場合は、そのようには呼び出していないので、明示的に <code>&amp;b</code> を渡してやる必要があります。</p>
289311

290-
<h1 id='angle-bracket-form' class='section-header'><a href='#angle-bracket-form'>Angle-bracket Form</a></h1>
291-
<p>The form of UFCS we just talked about:</p>
312+
<h1 id='山括弧形式' class='section-header'><a href='#山括弧形式'>山括弧形式</a></h1>
313+
<!-- The form of UFCS we just talked about: -->
314+
315+
<p>すぐ上で説明した、以下のような共通の関数呼び出し構文:</p>
292316
<span class='rusttest'>fn main() {
293317
Trait::method(args);
294318
}</span><pre class='rust rust-example-rendered'>
295319
<span class='ident'>Trait</span>::<span class='ident'>method</span>(<span class='ident'>args</span>);</pre>
296320

297-
<p>Is a short-hand. There’s an expanded form of this that’s needed in some
298-
situations:</p>
321+
<!-- Is a short-hand. There’s an expanded form of this that’s needed in some -->
322+
323+
<!-- situations: -->
324+
325+
<p>これは短縮形であり、時々必要になる以下の様な展開された形式もあります:</p>
299326
<span class='rusttest'>fn main() {
300327
&lt;Type as Trait&gt;::method(args);
301328
}</span><pre class='rust rust-example-rendered'>
302329
<span class='op'>&lt;</span><span class='ident'>Type</span> <span class='kw'>as</span> <span class='ident'>Trait</span><span class='op'>&gt;</span>::<span class='ident'>method</span>(<span class='ident'>args</span>);</pre>
303330

304-
<p>The <code>&lt;&gt;::</code> syntax is a means of providing a type hint. The type goes inside
305-
the <code>&lt;&gt;</code>s. In this case, the type is <code>Type as Trait</code>, indicating that we want
306-
<code>Trait</code>’s version of <code>method</code> to be called here. The <code>as Trait</code> part is
307-
optional if it’s not ambiguous. Same with the angle brackets, hence the
308-
shorter form.</p>
331+
<!-- The `<>::` syntax is a means of providing a type hint. The type goes inside -->
332+
333+
<!-- the `<>`s. In this case, the type is `Type as Trait`, indicating that we want -->
334+
335+
<!-- `Trait`’s version of `method` to be called here. The `as Trait` part is -->
336+
337+
<!-- optional if it’s not ambiguous. Same with the angle brackets, hence the -->
309338

310-
<p>Here’s an example of using the longer form.</p>
339+
<!-- shorter form. -->
340+
341+
<p><code>&lt;&gt;::</code> という構文は型のヒントを意味しており、 <code>&lt;&gt;</code> のなかに型が入ります。
342+
この場合、型は <code>Type as Trait</code> となり、 <code>Trait</code>のバージョンの <code>method</code> が呼ばれる事を期待していることを意味しています。
343+
<code>as Trait</code> という部分は、曖昧でない場合は省略可能です。山括弧についても同様に省略可能であり、なので先程のさらに短い形になるのです。</p>
344+
345+
<!-- Here’s an example of using the longer form. -->
346+
347+
<p>長い形式を用いたサンプルコードは以下の通りです:</p>
311348
<span class='rusttest'>trait Foo {
312349
fn foo() -&gt; i32;
313350
}
@@ -354,8 +391,11 @@ <h1 id='angle-bracket-form' class='section-header'><a href='#angle-bracket-form'
354391
<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='number'>20</span>, <span class='ident'>Bar</span>::<span class='ident'>foo</span>());
355392
}</pre>
356393

357-
<p>Using the angle bracket syntax lets you call the trait method instead of the
358-
inherent one.</p>
394+
<!-- Using the angle bracket syntax lets you call the trait method instead of the -->
395+
396+
<!-- inherent one. -->
397+
398+
<p>山括弧構文を用いることでトレイトのメソッドを継承されたメソッドの代わりに呼び出すことができます。</p>
359399

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

0 commit comments

Comments
 (0)