Skip to content

Commit a7036cd

Browse files
committed
Merge pull request #57 from pocket7878/universal-function-call-syntax
Universal function call syntax.
2 parents 1575332 + f2af4ce commit a7036cd

File tree

2 files changed

+108
-88
lines changed

2 files changed

+108
-88
lines changed

1.6/ja/book/ufcs.md

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
% Universal Function Call Syntax
1+
% 共通の関数呼び出し構文
2+
<!-- % Universal Function Call Syntax -->
23

3-
Sometimes, functions can have the same names. Consider this code:
4+
<!-- Sometimes, functions can have the same names. Consider this code: -->
5+
しばしば、同名の関数が存在する時があります。たとえば、以下のコードでは:
46

57
```rust
68
trait Foo {
@@ -24,7 +26,8 @@ impl Bar for Baz {
2426
let b = Baz;
2527
```
2628

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

2932
```text
3033
error: multiple applicable methods in scope [E0034]
@@ -41,8 +44,12 @@ note: candidate #2 is defined in an impl of the trait `main::Bar` for the type
4144
4245
```
4346

44-
We need a way to disambiguate which method we need. This feature is called
45-
‘universal function call syntax’, and it looks like this:
47+
<!-- We need a way to disambiguate which method we need. This feature is called -->
48+
<!-- ‘universal function call syntax’, and it looks like this: -->
49+
このような場合は、どのメソッドを呼び出す必要があるのかについて曖昧性を排除する手段が必要です。
50+
そのようなフィーチャーは 「共通の関数呼び出し構文」と呼ばれ、以下のように書けます:
51+
52+
4653

4754
```rust
4855
# trait Foo {
@@ -63,49 +70,60 @@ Foo::f(&b);
6370
Bar::f(&b);
6471
```
6572

66-
Let’s break it down.
73+
<!-- Let’s break it down. -->
74+
部分的に見ていきましょう。
6775

6876
```rust,ignore
6977
Foo::
7078
Bar::
7179
```
7280

73-
These halves of the invocation are the types of the two traits: `Foo` and
74-
`Bar`. This is what ends up actually doing the disambiguation between the two:
75-
Rust calls the one from the trait name you use.
81+
<!-- These halves of the invocation are the types of the two traits: `Foo` and -->
82+
<!-- `Bar`. This is what ends up actually doing the disambiguation between the two: -->
83+
<!-- Rust calls the one from the trait name you use. -->
84+
まず、呼び出しのこの部分は2つのトレイト `Foo``Bar` の型を表しています。
85+
この部分が、実際にどちらのトレイトのメソッドを呼び出しているのかを指定し、曖昧性を排除している箇所になります。
7686

7787
```rust,ignore
7888
f(&b)
7989
```
8090

81-
When we call a method like `b.f()` using [method syntax][methodsyntax], Rust
82-
will automatically borrow `b` if `f()` takes `&self`. In this case, Rust will
83-
not, and so we need to pass an explicit `&b`.
91+
<!-- When we call a method like `b.f()` using [method syntax][methodsyntax], Rust -->
92+
<!-- will automatically borrow `b` if `f()` takes `&self`. In this case, Rust will -->
93+
<!-- not, and so we need to pass an explicit `&b`. -->
94+
`b.f()` のように [メソッド構文][methodsyntax] を利用して呼び出した時、Rustは `f()``&self` を引数に取る場合自動的に `b` を借用します。
95+
今回の場合は、そのようには呼び出していないので、明示的に `&b` を渡してやる必要があります。
8496

8597
[methodsyntax]: method-syntax.html
8698

87-
# Angle-bracket Form
99+
# 山括弧形式
88100

89-
The form of UFCS we just talked about:
101+
<!-- The form of UFCS we just talked about: -->
102+
すぐ上で説明した、以下のような共通の関数呼び出し構文:
90103

91104
```rust,ignore
92105
Trait::method(args);
93106
```
94107

95-
Is a short-hand. There’s an expanded form of this that’s needed in some
96-
situations:
108+
<!-- Is a short-hand. There’s an expanded form of this that’s needed in some -->
109+
<!-- situations: -->
110+
これは短縮形であり、時々必要になる以下の様な展開された形式もあります:
97111

98112
```rust,ignore
99113
<Type as Trait>::method(args);
100114
```
101115

102-
The `<>::` syntax is a means of providing a type hint. The type goes inside
103-
the `<>`s. In this case, the type is `Type as Trait`, indicating that we want
104-
`Trait`’s version of `method` to be called here. The `as Trait` part is
105-
optional if it’s not ambiguous. Same with the angle brackets, hence the
106-
shorter form.
116+
<!-- The `<>::` syntax is a means of providing a type hint. The type goes inside -->
117+
<!-- the `<>`s. In this case, the type is `Type as Trait`, indicating that we want -->
118+
<!-- `Trait`’s version of `method` to be called here. The `as Trait` part is -->
119+
<!-- optional if it’s not ambiguous. Same with the angle brackets, hence the -->
120+
<!-- shorter form. -->
121+
`<>::` という構文は型のヒントを意味しており、 `<>` のなかに型が入ります。
122+
この場合、型は `Type as Trait` となり、 `Trait`のバージョンの `method` が呼ばれる事を期待していることを意味しています。
123+
`as Trait` という部分は、曖昧でない場合は省略可能です。山括弧についても同様に省略可能であり、なので先程のさらに短い形になるのです。
107124

108-
Here’s an example of using the longer form.
125+
<!-- Here’s an example of using the longer form. -->
126+
長い形式を用いたサンプルコードは以下の通りです:
109127

110128
```rust
111129
trait Foo {
@@ -132,5 +150,6 @@ fn main() {
132150
}
133151
```
134152

135-
Using the angle bracket syntax lets you call the trait method instead of the
136-
inherent one.
153+
<!-- Using the angle bracket syntax lets you call the trait method instead of the -->
154+
<!-- inherent one. -->
155+
山括弧構文を用いることでトレイトのメソッドを継承されたメソッドの代わりに呼び出すことができます。

TranslationTable.md

Lines changed: 65 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -8,67 +8,68 @@
88

99
# 対訳表
1010

11-
| English | 日本語
12-
|:----------------------|:------
13-
| alignment | アラインメント
14-
| allocator | アロケータ
15-
| application | アプリケーション
16-
| arity | アリティ
17-
| array | 配列
18-
| associated - | 関連-
19-
| attribute | アトリビュート
20-
| binary | バイナリ
21-
| binding | 束縛
22-
| block | ブロック
23-
| borrowing | 借用
24-
| capture | キャプチャ
25-
| closure | クロージャ
26-
| coercion | 型強制
27-
| compiler | コンパイラ
28-
| constant | 定数
29-
| crate | クレート
30-
| declaration statement | 宣言文
31-
| dereferencing | 参照外し
32-
| destructuring | 分配
33-
| directive | ディレクティブ
34-
| distribution | 配布物
35-
| diverge | ダイバージ
36-
| diverging | ダイバージング
37-
| documentation comment | ドキュメンテーションコメント
38-
| documentation test | ドキュメンテーションテスト
39-
| early return | 早期リターン
40-
| enum | 列挙型
41-
| expression statement | 式文
42-
| feature | フィーチャ
43-
| generics | ジェネリクス
44-
| identifier | 識別子
45-
| immutable | イミュータブル
46-
| Intrinsics | Intrinsic
47-
| Lang Items | Lang Item
48-
| library | ライブラリ
49-
| lifetime | ライフタイム
50-
| link | リンク
51-
| lint | リント
52-
| match | マッチ
53-
| memory | メモリ
54-
| move | ムーブ
55-
| mutable | ミュータブル
56-
| mutability | ミュータビリティ
57-
| owner | 所有者
58-
| ownership | 所有権
59-
| panic | パニック
60-
| return | 返す
61-
| shadow | 覆い隠す
62-
| signature | シグネチャ
63-
| slice | スライス
64-
| slicing | スライシング
65-
| struct | 構造体
66-
| structure | ストラクチャ
67-
| symbol | シンボル
68-
| syntactic sugar | 糖衣構文
69-
| system | システム
70-
| tick | クオート
71-
| trait | トレイト
72-
| unsized type | サイズ不定型
73-
| vector | ベクタ
74-
| wildcard | ワイルドカード
11+
| English | 日本語
12+
|:-------------------------------|:-------------
13+
| alignment | アラインメント
14+
| allocator | アロケータ
15+
| application | アプリケーション
16+
| arity | アリティ
17+
| array | 配列
18+
| associated - | 関連-
19+
| attribute | アトリビュート
20+
| binary | バイナリ
21+
| binding | 束縛
22+
| block | ブロック
23+
| borrowing | 借用
24+
| capture | キャプチャ
25+
| closure | クロージャ
26+
| coercion | 型強制
27+
| compiler | コンパイラ
28+
| constant | 定数
29+
| crate | クレート
30+
| declaration statement | 宣言文
31+
| dereferencing | 参照外し
32+
| destructuring | 分配
33+
| directive | ディレクティブ
34+
| distribution | 配布物
35+
| diverge | ダイバージ
36+
| diverging | ダイバージング
37+
| documentation comment | ドキュメンテーションコメント
38+
| documentation test | ドキュメンテーションテスト
39+
| early return | 早期リターン
40+
| enum | 列挙型
41+
| expression statement | 式文
42+
| feature | フィーチャ
43+
| generics | ジェネリクス
44+
| identifier | 識別子
45+
| immutable | イミュータブル
46+
| Intrinsics | Intrinsic
47+
| Lang Items | Lang Item
48+
| library | ライブラリ
49+
| lifetime | ライフタイム
50+
| link | リンク
51+
| lint | リント
52+
| match | マッチ
53+
| memory | メモリ
54+
| move | ムーブ
55+
| mutable | ミュータブル
56+
| mutability | ミュータビリティ
57+
| owner | 所有者
58+
| ownership | 所有権
59+
| panic | パニック
60+
| return | 返す
61+
| shadow | 覆い隠す
62+
| signature | シグネチャ
63+
| slice | スライス
64+
| slicing | スライシング
65+
| struct | 構造体
66+
| structure | ストラクチャ
67+
| symbol | シンボル
68+
| syntactic sugar | 糖衣構文
69+
| system | システム
70+
| tick | クオート
71+
| trait | トレイト
72+
| Universal Function Call Syntax | 共通の関数呼び出し構文
73+
| unsized type | サイズ不定型
74+
| vector | ベクタ
75+
| wildcard | ワイルドカード

0 commit comments

Comments
 (0)