Skip to content

Commit 2f3f7a6

Browse files
committed
generate
1 parent 55b2fb3 commit 2f3f7a6

File tree

1 file changed

+45
-16
lines changed

1 file changed

+45
-16
lines changed

public/1.6/book/type-aliases.html

Lines changed: 45 additions & 16 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>`type` Aliases</title>
7+
<title>`type` エイリアス</title>
88

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

@@ -185,14 +185,20 @@
185185
<div id='page'>
186186

187187

188-
<h1 class="title">`type` Aliases</h1>
189-
<p>The <code>type</code> keyword lets you declare an alias of another type:</p>
188+
<h1 class="title">`type` エイリアス</h1>
189+
<!-- % `type` Aliases -->
190+
191+
<!-- The `type` keyword lets you declare an alias of another type: -->
192+
193+
<p><code>type</code> キーワードを用いることで他の型へのエイリアスを宣言することができます:</p>
190194
<span class='rusttest'>fn main() {
191195
type Name = String;
192196
}</span><pre class='rust rust-example-rendered'>
193197
<span class='kw'>type</span> <span class='ident'>Name</span> <span class='op'>=</span> <span class='ident'>String</span>;</pre>
194198

195-
<p>You can then use this type as if it were a real type:</p>
199+
<!-- You can then use this type as if it were a real type: -->
200+
201+
<p>このようにすると 定義した型を実際の型であるかのように利用することができます:</p>
196202
<span class='rusttest'>fn main() {
197203
type Name = String;
198204

@@ -202,9 +208,15 @@ <h1 class="title">`type` Aliases</h1>
202208

203209
<span class='kw'>let</span> <span class='ident'>x</span>: <span class='ident'>Name</span> <span class='op'>=</span> <span class='string'>&quot;Hello&quot;</span>.<span class='ident'>to_string</span>();</pre>
204210

205-
<p>Note, however, that this is an <em>alias</em>, not a new type entirely. In other
206-
words, because Rust is strongly typed, you’d expect a comparison between two
207-
different types to fail:</p>
211+
<!-- Note, however, that this is an _alias_, not a new type entirely. In other -->
212+
213+
<!-- words, because Rust is strongly typed, you’d expect a comparison between two -->
214+
215+
<!-- different types to fail: -->
216+
217+
<p>しかしながら、これはあくまで <em>エイリアス</em> であって、新しい型ではありません。
218+
言い換えると、Rustは強い型付け言語であるため、異なる型同士の比較が失敗することを期待するでしょう。
219+
例えば:</p>
208220
<span class='rusttest'>fn main() {
209221
let x: i32 = 5;
210222
let y: i64 = 5;
@@ -220,7 +232,9 @@ <h1 class="title">`type` Aliases</h1>
220232
<span class='comment'>// ...</span>
221233
}</pre>
222234

223-
<p>this gives</p>
235+
<!-- this gives -->
236+
237+
<p>このようなコードは以下のエラーを発生させます:</p>
224238

225239
<pre><code class="language-text">error: mismatched types:
226240
expected `i32`,
@@ -231,7 +245,9 @@ <h1 class="title">`type` Aliases</h1>
231245
^
232246
</code></pre>
233247

234-
<p>But, if we had an alias:</p>
248+
<!-- But, if we had an alias: -->
249+
250+
<p>一方で、エイリアス用いた場合は:</p>
235251
<span class='rusttest'>fn main() {
236252
type Num = i32;
237253

@@ -251,10 +267,16 @@ <h1 class="title">`type` Aliases</h1>
251267
<span class='comment'>// ...</span>
252268
}</pre>
253269

254-
<p>This compiles without error. Values of a <code>Num</code> type are the same as a value of
255-
type <code>i32</code>, in every way. You can use <a href="structs.html#tuple-structs">tuple struct</a> to really get a new type.</p>
270+
<!-- This compiles without error. Values of a `Num` type are the same as a value of -->
256271

257-
<p>You can also use type aliases with generics:</p>
272+
<!-- type `i32`, in every way. You can use [tuple struct] to really get a new type. -->
273+
274+
<p>このコードはエラーを起こすこと無くコンパイルを通ります。 <code>Num</code> 型の値は <code>i32</code> 型の値とすべての面において等価です。
275+
本当に新しい型がほしい時は <a href="structs.html#tuple-structs">タプル構造体</a> を使うことができます。</p>
276+
277+
<!-- You can also use type aliases with generics: -->
278+
279+
<p>また、エイリアスをジェネリクスと共に利用する事もできます:</p>
258280
<span class='rusttest'>fn main() {
259281
use std::result;
260282

@@ -274,10 +296,17 @@ <h1 class="title">`type` Aliases</h1>
274296

275297
<span class='kw'>type</span> <span class='prelude-ty'>Result</span><span class='op'>&lt;</span><span class='ident'>T</span><span class='op'>&gt;</span> <span class='op'>=</span> <span class='ident'>result</span>::<span class='prelude-ty'>Result</span><span class='op'>&lt;</span><span class='ident'>T</span>, <span class='ident'>ConcreteError</span><span class='op'>&gt;</span>;</pre>
276298

277-
<p>This creates a specialized version of the <code>Result</code> type, which always has a
278-
<code>ConcreteError</code> for the <code>E</code> part of <code>Result&lt;T, E&gt;</code>. This is commonly used
279-
in the standard library to create custom errors for each subsection. For
280-
example, <a href="../std/io/type.Result.html">io::Result</a>.</p>
299+
<!-- This creates a specialized version of the `Result` type, which always has a -->
300+
301+
<!-- `ConcreteError` for the `E` part of `Result<T, E>`. This is commonly used -->
302+
303+
<!-- in the standard library to create custom errors for each subsection. For -->
304+
305+
<!-- example, [io::Result][ioresult]. -->
306+
307+
<p>このようにすると <code>Result</code> 型の <code>Result&lt;T, E&gt;</code><code>E</code> として常に <code>ConcreteError</code> を持っている特殊化されたバージョンが定義されます。
308+
このような方法は標準ライブラリで細かく分類されたエラーを定義するために頻繁に使われています。
309+
一例を上げると <a href="../std/io/type.Result.html">io::Result</a> がそれに当たります。</p>
281310

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

0 commit comments

Comments
 (0)