Skip to content

4.13 - 列挙型 enums (1.9) #234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions 1.9/en/book/enums.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
% Enums

An `enum` in Rust is a type that represents data that could be one of
several possible variants:
An `enum` in Rust is a type that represents data that is one of
several possible variants. Each variant in the `enum` can optionally
have data associated with it:

```rust
enum Message {
Expand All @@ -12,9 +13,8 @@ enum Message {
}
```

Each variant can optionally have data associated with it. The syntax for
defining variants resembles the syntaxes used to define structs: you can
have variants with no data (like unit-like structs), variants with named
The syntax for defining variants resembles the syntaxes used to define structs:
you can have variants with no data (like unit-like structs), variants with named
data, and variants with unnamed data (like tuple structs). Unlike
separate struct definitions, however, an `enum` is a single type. A
value of the enum can match any of the variants. For this reason, an
Expand All @@ -41,7 +41,7 @@ let y: BoardGameTurn = BoardGameTurn::Move { squares: 1 };
Both variants are named `Move`, but since they’re scoped to the name of
the enum, they can both be used without conflict.

A value of an enum type contains information about which variant it is,
A value of an `enum` type contains information about which variant it is,
in addition to any data associated with that variant. This is sometimes
referred to as a ‘tagged union’, since the data includes a ‘tag’
indicating what type it is. The compiler uses this information to
Expand All @@ -62,12 +62,11 @@ learn in the next section. We don’t know enough about Rust to implement
equality yet, but we’ll find out in the [`traits`][traits] section.

[match]: match.html
[if-let]: if-let.html
[traits]: traits.html

# Constructors as functions

An enum’s constructors can also be used like functions. For example:
An `enum` constructor can also be used like a function. For example:

```rust
# enum Message {
Expand All @@ -76,7 +75,7 @@ An enum’s constructors can also be used like functions. For example:
let m = Message::Write("Hello, world".to_string());
```

Is the same as
is the same as

```rust
# enum Message {
Expand Down
19 changes: 9 additions & 10 deletions 1.9/ja/book/enums.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
% 列挙型
<!-- % Enums -->

<!-- An `enum` in Rust is a type that represents data that could be one of
several possible variants: -->
<!-- An `enum` in Rust is a type that represents data that is one of
several possible variants. Each variant in the `enum` can optionally
have data associated with it: -->
Rustの `enum` は、いくつかのヴァリアントのうちからどれか一つをとるデータを表す型です。
`enum` の各ヴァリアントは、それぞれ自身に関連するデータを持つこともできます。

```rust
enum Message {
Expand All @@ -14,15 +16,13 @@ enum Message {
}
```

<!-- Each variant can optionally have data associated with it. The syntax for
defining variants resembles the syntaxes used to define structs: you can
have variants with no data (like unit-like structs), variants with named
<!-- The syntax for defining variants resembles the syntaxes used to define structs:
you can have variants with no data (like unit-like structs), variants with named
data, and variants with unnamed data (like tuple structs). Unlike
separate struct definitions, however, an `enum` is a single type. A
value of the enum can match any of the variants. For this reason, an
enum is sometimes called a ‘sum type’: the set of possible values of the
enum is the sum of the sets of possible values for each variant. -->
各ヴァリアントは、自身に関連するデータを持つこともできます。
ヴァリアントの定義のための構文は、構造体を定義するのに使われる構文と似ており、
(unit-like構造体のような) データを持たないヴァリアント、名前付きデータを持つヴァリアント、 (タプル構造体のような) 名前なしデータを持つヴァリアントがありえます。
しかし、別々に構造体を定義する場合とは異なり、 `enum` は一つの型です。
Expand Down Expand Up @@ -54,7 +54,7 @@ let y: BoardGameTurn = BoardGameTurn::Move { squares: 1 };
the enum, they can both be used without conflict. -->
どちらのヴァリアントも `Move` という名前ですが、列挙型の名前でスコープ化されているため、衝突することなく使うことができます。

<!-- A value of an enum type contains information about which variant it is,
<!-- A value of an `enum` type contains information about which variant it is,
in addition to any data associated with that variant. This is sometimes
referred to as a ‘tagged union’, since the data includes a ‘tag’
indicating what type it is. The compiler uses this information to
Expand Down Expand Up @@ -85,13 +85,12 @@ equality yet, but we’ll find out in the [`traits`][traits] section. -->
等値性を実装するにはRustについてまだ知るべきことがありますが、 [`トレイト`][traits] のセクションに書いてあります。

[match]: match.html
[if-let]: if-let.html
[traits]: traits.html

<!-- # Constructors as functions -->
# 関数としてのコンストラクタ

<!-- An enum’s constructors can also be used like functions. For example: -->
<!-- An `enum` constructor can also be used like a function. For example: -->
列挙型のコンストラクタも、関数のように使うことができます。
例えばこうです。

Expand All @@ -102,7 +101,7 @@ equality yet, but we’ll find out in the [`traits`][traits] section. -->
let m = Message::Write("Hello, world".to_string());
```

<!-- Is the same as -->
<!-- is the same as -->
これは、以下と同じです。

```rust
Expand Down
58 changes: 0 additions & 58 deletions diff-1.6.0..1.9.0/src/doc/book/enums.md

This file was deleted.