From 9657b15119059ad3819e582274fd4711d559385d Mon Sep 17 00:00:00 2001 From: Nnwww Date: Tue, 2 Feb 2016 09:51:03 +0900 Subject: [PATCH 1/7] start translating --- 1.6/ja/book/traits.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/1.6/ja/book/traits.md b/1.6/ja/book/traits.md index f9e3299f..0224d1b3 100644 --- a/1.6/ja/book/traits.md +++ b/1.6/ja/book/traits.md @@ -1,4 +1,5 @@ -% Traits +% トレイト + A trait is a language feature that tells the Rust compiler about functionality a type must provide. From 657e072c91b5038a175f37e356b30faed14ffa23 Mon Sep 17 00:00:00 2001 From: Nnwww Date: Wed, 3 Feb 2016 01:23:47 +0900 Subject: [PATCH 2/7] translate a half --- 1.6/ja/book/glossary.md | 8 ++-- 1.6/ja/book/traits.md | 92 +++++++++++++++++++++++++---------------- 2 files changed, 62 insertions(+), 38 deletions(-) diff --git a/1.6/ja/book/glossary.md b/1.6/ja/book/glossary.md index 3afbaea5..d71ca264 100644 --- a/1.6/ja/book/glossary.md +++ b/1.6/ja/book/glossary.md @@ -38,11 +38,13 @@ let z = (8, 2, 6); In the example above `x` and `y` have arity 2. `z` has arity 3. -### Bounds + +### 境界 -Bounds are constraints on a type or [trait][traits]. For example, if a bound + +境界(Bounds)とはある1つの型または [トレイト][traits] における制約のことです。例えば、ある関数がとる引数に境界が設定されたとすると、その関数に渡される型は設定された制約に必ず従わなければなりません。 [traits]: traits.html diff --git a/1.6/ja/book/traits.md b/1.6/ja/book/traits.md index 0224d1b3..a3b2da56 100644 --- a/1.6/ja/book/traits.md +++ b/1.6/ja/book/traits.md @@ -1,11 +1,13 @@ % トレイト -A trait is a language feature that tells the Rust compiler about -functionality a type must provide. + +トレイトはある型が提供しなければならない機能をRustのコンパイラに伝える言語機能です。 -Recall the `impl` keyword, used to call a function with [method -syntax][methodsyntax]: + +[メソッド構文][methodsyntax]で関数を呼び出すのに用いていた、 `impl` キーワードを思い出して下さい。 ```rust struct Circle { @@ -23,8 +25,10 @@ impl Circle { [methodsyntax]: method-syntax.html -Traits are similar, except that we first define a trait with a method -signature, then implement the trait for a type. In this example, we implement the trait `HasArea` for `Circle`: + +トレイトはそれに似ていますが、始めにトレイトをメソッドのシグネチャと共に定義し、続いてある型のためにトレイトを実装するという流れが異なります。 +この例では、 `Circle` のために `HasArea` トレイトを実装しています。 ```rust struct Circle { @@ -44,15 +48,18 @@ impl HasArea for Circle { } ``` -As you can see, the `trait` block looks very similar to the `impl` block, + +このように、 `trait` ブロックは `impl` ブロックにとても似ているように見えますが、関数本体を定義せず、型シグネチャだけを定義しています。トレイトを `impl` するときは、ただ `impl Item` とするのではなく、 `impl Trait for Item` と記述します。 -## Trait bounds on generic functions + +## ジェネリック関数におけるトレイト境界 -Traits are useful because they allow a type to make certain promises about its + +トレイトはある型の振る舞いを確約してくれるため有用です。ジェネリック関数は制約、あるいは [境界][bounds] が許容する型のみを受け取るためにトレイトを利用できます。以下の関数を考えて下さい、これはコンパイルできません。 [bounds]: glossary.html#bounds @@ -62,15 +69,17 @@ fn print_area(shape: T) { } ``` -Rust complains: + +Rustは以下のエラーを吐きます。 ```text error: no method named `area` found for type `T` in the current scope ``` -Because `T` can be any type, we can’t be sure that it implements the `area` + +`T` はあらゆる型になれるため、 `area` メソッドが実装されているか確認できません。ですが私たちはジェネリックな `T` にトレイト境界を追加できるので、境界が実装を保証してくれます。 ```rust # trait HasArea { @@ -81,11 +90,13 @@ fn print_area(shape: T) { } ``` -The syntax `` means “any type that implements the `HasArea` trait.” + +`` 構文は「 `HasArea` トレイトを実装するあらゆる型」という意味です。トレイトは関数の型シグネチャを定義しているため、 `HasArea` を実装するあらゆる型が `.area()` メソッドを持っていることを確認できます。 -Here’s an extended example of how this works: + +トレイトの動作を確認するために拡張した例が以下になります。 ```rust trait HasArea { @@ -138,31 +149,36 @@ fn main() { } ``` -This program outputs: + +このプログラムの出力は、 ```text This shape has an area of 3.141593 This shape has an area of 1 ``` -As you can see, `print_area` is now generic, but also ensures that we have -passed in the correct types. If we pass in an incorrect type: + +見ての通り、上記の `print_area` はジェネリックですが、適切な型が渡されることを保証しています。もし不適切な型を渡すと、 ```rust,ignore print_area(5); ``` -We get a compile-time error: + +コンパイル時エラーが発生します。 ```text error: the trait `HasArea` is not implemented for the type `_` [E0277] ``` -## Trait bounds on generic structs + +## ジェネリック構造体におけるトレイト境界 -Your generic structs can also benefit from trait bounds. All you need to + +ジェネリック構造体もトレイト境界による恩恵を受けることができます。あなたがしなければならないのは型パラメータを宣言する際に境界を追加することだけです。以下が新しい型 `Rectangle` とそのメソッド `is_square()` です。 ```rust struct Rectangle { @@ -193,31 +209,36 @@ fn main() { } ``` -`is_square()` needs to check that the sides are equal, so the sides must be of -a type that implements the [`core::cmp::PartialEq`][PartialEq] trait: + +`is_square()` は両辺が等しいかチェックする必要があるため、両辺の型は [`core::cmp::PartialEq`][PartialEq] トレイトを実装しなければなりません。 ```ignore impl Rectangle { ... } ``` -Now, a rectangle can be defined in terms of any type that can be compared for -equality. + +今、比較して等しさを確かめることのできる型という観点から長方形を定義できました。 [PartialEq]: ../core/cmp/trait.PartialEq.html -Here we defined a new struct `Rectangle` that accepts numbers of any + +上記の例では任意の精度を許容する `Rectangle` 構造体を新たに定義しました-実のところ、比較して等しさを確かめることのできるほぼ全ての型に対して利用可能なオブジェクトです。同じことを `Square` や `Circle` のような `HasArea` を実装する構造体に対してできるでしょうか?可能では有りますが乗算が必要になるため、それをするには [オペレータトレイト][operators-and-overloading] についてより詳しく知らなければなりません。 [operators-and-overloading]: operators-and-overloading.html -# Rules for implementing traits + +# トレイト実装のルール -So far, we’ve only added trait implementations to structs, but you can + +ここまでで、構造体へトレイトの実装を追加することだけを説明してきましたが、あらゆる型についてトレイトを実装することができます。技術的には、 `i32` のための `HasArea` を実装することも _できなくはない_ です。 ```rust trait HasArea { @@ -235,8 +256,9 @@ impl HasArea for i32 { 5.area(); ``` -It is considered poor style to implement methods on such primitive types, even -though it is possible. + +しかし例え可能であったとしても、そのようなプリミティブ型のメソッドを実装するのは拙い手法だと考えられています。 This may seem like the Wild West, but there are two restrictions around implementing traits that prevent this from getting out of hand. The first is From ff814bc0fd1c0cfafb2bb65402878d2e262edbb9 Mon Sep 17 00:00:00 2001 From: Nnwww Date: Thu, 4 Feb 2016 23:19:09 +0900 Subject: [PATCH 3/7] finish a provisional translation --- 1.6/ja/book/traits.md | 124 +++++++++++++++++++++++++++--------------- 1 file changed, 81 insertions(+), 43 deletions(-) diff --git a/1.6/ja/book/traits.md b/1.6/ja/book/traits.md index a3b2da56..cb3f71f8 100644 --- a/1.6/ja/book/traits.md +++ b/1.6/ja/book/traits.md @@ -260,23 +260,27 @@ impl HasArea for i32 { though it is possible. --> しかし例え可能であったとしても、そのようなプリミティブ型のメソッドを実装するのは拙い手法だと考えられています。 -This may seem like the Wild West, but there are two restrictions around + +ここまでくると何でもありなように思えますが、手が負えなくなることを防ぐためにトレイトの実装周りには2つの制限が設けられています。第1に、あなたのスコープ内で定義されていないトレイトは適用されません。例えば、標準ライブラリは `File` にI/O機能を追加するための `Write` トレイトを提供しています。デフォルトでは、 `File` はそのメソッドを持っていません。 [write]: ../std/io/trait.Write.html ```rust,ignore let mut f = std::fs::File::open("foo.txt").expect("Couldn’t open foo.txt"); -let buf = b"whatever"; // byte string literal. buf: &[u8; 8] +# let buf = b"whatever"; // byte string literal. buf: &[u8; 8] +let buf = b"whatever"; // buf: &[u8; 8] はバイト文字列リテラルです。 let result = f.write(buf); # result.unwrap(); // ignore the error +# result.unwrap(); // エラーを無視します。 ``` -Here’s the error: + +エラーは以下のようになります。 ```text error: type `std::fs::File` does not implement any method in scope named `write` @@ -284,7 +288,8 @@ let result = f.write(buf); ^~~~~~~~~~ ``` -We need to `use` the `Write` trait first: + +始めに `Write` トレイトを `use` する必要があります。 ```rust,ignore use std::io::Write; @@ -295,26 +300,32 @@ let result = f.write(buf); # result.unwrap(); // ignore the error ``` -This will compile without error. + +これはエラー無しでコンパイルされます。 -This means that even if someone does something bad like add methods to `i32`, -it won’t affect you, unless you `use` that trait. + +これは、例え誰かが `i32` へメソッドを追加するような望ましくない何かを行ったとしても、あなたがトレイトを `use` しない限り、影響はないことを意味します。 -There’s one more restriction on implementing traits: either the trait, or the + +トレイトの実装における制限はもう1つあります。トレイト、またはあなたが書いている `impl` の対象となる型は、あなた自身によって実装されなければなりません。 `HasArea` は私たちが記述したコードであるため、 `i32` のための `HasArea` を実装することができます。しかし、 `i32` のためにRustによって提供されている `ToString` トレイトを実装したいとしても、トレイトと型が共に私たちの記述したコードでないため、それはできません。 -One last thing about traits: generic functions with a trait bound use + +トレイトに関して最後に1つ。トレイトによって束縛されたジェネリック関数は「モノモーフィゼーション」(monomorphization)(mono:単一の、morph:様相)されるため、静的ディスパッチが行われます。一体どういう意味でしょうか?詳細については、[トレイトオブジェクト][to]の章をチェックしてください。 [to]: trait-objects.html -# Multiple trait bounds + +# 複数のトレイト境界 -You’ve seen that you can bound a generic type parameter with a trait: + +トレイトでジェネリックな型パラメータに境界が与えられることを見てきました。 ```rust fn foo(x: T) { @@ -322,7 +333,8 @@ fn foo(x: T) { } ``` -If you need more than one bound, you can use `+`: + +1つ以上の境界を与えたい場合、 `+` を使えます。 ```rust use std::fmt::Debug; @@ -333,13 +345,16 @@ fn foo(x: T) { } ``` -`T` now needs to be both `Clone` as well as `Debug`. + +この `T` 型は `Clone` と `Debug` 両方が必要です。 -# Where clause + +# Where 節 -Writing functions with only a few generic types and a small number of trait + +ジェネリック型もトレイト境界の数も少ない関数を書いているうちは悪く無いのですが、数が増えるとこの構文ではいよいよ不便になってきます。 ```rust use std::fmt::Debug; @@ -351,10 +366,13 @@ fn foo(x: T, y: K) { } ``` -The name of the function is on the far left, and the parameter list is on the -far right. The bounds are getting in the way. + +関数名は左端にあり、引数リストは右端にあります。境界を記述する部分が邪魔になっているのです。 -Rust has a solution, and it’s called a ‘`where` clause’: + + +Rustは「`where` 節」と呼ばれる解決策を持っています。 ```rust use std::fmt::Debug; @@ -377,10 +395,11 @@ fn main() { } ``` -`foo()` uses the syntax we showed earlier, and `bar()` uses a `where` clause. + +`foo()` は先程見せたままの構文で、 `bar()` は `where` 節を用いています。あなたに必要なのは型パラメータの定義時に境界の設定をやめ、引数リストの後ろに `where` を追加することだけです。長いリストであれば、空白を加えることもできます。 ```rust use std::fmt::Debug; @@ -395,9 +414,11 @@ fn bar(x: T, y: K) } ``` -This flexibility can add clarity in complex situations. + +この柔軟性により複雑な状況であっても明瞭さを付加することができます。 -`where` is also more powerful than the simpler syntax. For example: + +また、`where` は基本の構文よりも強力です。例えば、 ```rust trait ConvertTo { @@ -408,27 +429,33 @@ impl ConvertTo for i32 { fn convert(&self) -> i64 { *self as i64 } } -// can be called with T == i32 +# // can be called with T == i32 +// T == i32の時に呼び出せる fn normal>(x: &T) -> i64 { x.convert() } -// can be called with T == i64 +# // can be called with T == i64 +// T == i64の時に呼び出せる fn inverse() -> T - // this is using ConvertTo as if it were "ConvertTo" +# // this is using ConvertTo as if it were "ConvertTo" + // これは「ConvertTo」であるかのようにConvertToを用いている where i32: ConvertTo { 42.convert() } ``` -This shows off the additional feature of `where` clauses: they allow bounds + +ここでは `where` 節の追加機能を披露しています。この節は左辺に型パラメータ `T` だけでなく具体的な型(このケースでは `i32` )を指定できます。この例だと、 `i32` は `ConvertTo` を実装していなければなりません。(それは明らかですから)ここの `where` 節は `i32` が何であるかの定義というより、 `T` の制約といえるでしょう。 -# Default methods + +# デフォルトメソッド -A default method can be added to a trait definition if it is already known how a typical implementor will define a method. For example, `is_invalid()` is defined as the opposite of `is_valid()`: + +典型的な実装者がどうメソッドを定義するか既に分かっているならば、トレイトの定義にデフォルトメソッドを加えることができます。例えば、以下の `is_invalid()` は `is_valid()` の反対として定義されます。 ```rust trait Foo { @@ -438,7 +465,8 @@ trait Foo { } ``` -Implementors of the `Foo` trait need to implement `is_valid()` but not `is_invalid()` due to the added default behavior. This default behavior can still be overridden as in: + +`Foo` トレイトの実装者は `is_valid()` を実装する必要がありますが、デフォルトの動作が加えられている `is_invalid()` にはその必要がありません。 ```rust # trait Foo { @@ -465,20 +493,25 @@ impl Foo for OverrideDefault { fn is_invalid(&self) -> bool { println!("Called OverrideDefault.is_invalid!"); - true // overrides the expected value of is_invalid() +# // true // overrides the expected value of is_invalid() + true // 予期されるis_invalid()の値をオーバーライドする } } let default = UseDefault; -assert!(!default.is_invalid()); // prints "Called UseDefault.is_valid." +# // assert!(!default.is_invalid()); // prints "Called UseDefault.is_valid." +assert!(!default.is_invalid()); // 「Called UseDefault.is_valid.」を表示 let over = OverrideDefault; -assert!(over.is_invalid()); // prints "Called OverrideDefault.is_invalid!" +# // assert!(over.is_invalid()); // prints "Called OverrideDefault.is_invalid!" +assert!(over.is_invalid()); // 「Called OverrideDefault.is_invalid!」を表示 ``` -# Inheritance + +# 継承 -Sometimes, implementing a trait requires implementing another trait: + +時々、トレイトの実装に他のトレイトの実装が必要になることがあります。 ```rust trait Foo { @@ -491,6 +524,7 @@ trait FooBar : Foo { ``` Implementors of `FooBar` must also implement `Foo`, like this: +`FooBar` の実装者は以下のように `Foo` も実装しなければなりません。 ```rust # trait Foo { @@ -510,17 +544,20 @@ impl FooBar for Baz { } ``` -If we forget to implement `Foo`, Rust will tell us: + +`Foo` の実装を忘れると、Rustは以下のように伝えるでしょう。 ```text error: the trait `main::Foo` is not implemented for the type `main::Baz` [E0277] ``` + # Deriving -Implementing traits like `Debug` and `Default` repeatedly can become + +繰り返し`Debug` や `Default` のようなトレイトを実装するのは非常にうんざりさせられます。そのような理由から、Rustは自動的にトレイトを実装するための [アトリビュート][attributes] を提供しています。 ```rust #[derive(Debug)] @@ -533,7 +570,8 @@ fn main() { [attributes]: attributes.html -However, deriving is limited to a certain set of traits: + +ただし、derivingは以下の特定のトレイトに制限されています。 - [`Clone`](../core/clone/trait.Clone.html) - [`Copy`](../core/marker/trait.Copy.html) From b34f49d0ba881cb5ebcae61937da692c10713a3e Mon Sep 17 00:00:00 2001 From: Nnwww Date: Fri, 5 Feb 2016 18:42:03 +0900 Subject: [PATCH 4/7] fix translations --- 1.6/ja/book/traits.md | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/1.6/ja/book/traits.md b/1.6/ja/book/traits.md index cb3f71f8..6c3ac739 100644 --- a/1.6/ja/book/traits.md +++ b/1.6/ja/book/traits.md @@ -27,7 +27,7 @@ impl Circle { -トレイトはそれに似ていますが、始めにトレイトをメソッドのシグネチャと共に定義し、続いてある型のためにトレイトを実装するという流れが異なります。 +始めにトレイトをメソッドのシグネチャと共に定義し、続いてある型のためにトレイトを実装するという流れを除けばトレイトはメソッド構文に似ています。 この例では、 `Circle` のために `HasArea` トレイトを実装しています。 ```rust @@ -59,7 +59,7 @@ we use `impl Trait for Item`, rather than just `impl Item`. --> -トレイトはある型の振る舞いを確約してくれるため有用です。ジェネリック関数は制約、あるいは [境界][bounds] が許容する型のみを受け取るためにトレイトを利用できます。以下の関数を考えて下さい、これはコンパイルできません。 +トレイトはある型の振る舞いを確約できるため有用です。ジェネリック関数は制約、あるいは [境界][bounds] が許容する型のみを受け取るためにトレイトを利用できます。以下の関数を考えて下さい、これはコンパイルできません。 [bounds]: glossary.html#bounds @@ -79,7 +79,7 @@ error: no method named `area` found for type `T` in the current scope -`T` はあらゆる型になれるため、 `area` メソッドが実装されているか確認できません。ですが私たちはジェネリックな `T` にトレイト境界を追加できるので、境界が実装を保証してくれます。 +`T` はあらゆる型になれるため、 `area` メソッドが実装されているか確認できません。ですがジェネリックな `T` にはトレイト境界を追加でき、境界が実装を保証してくれます。 ```rust # trait HasArea { @@ -219,7 +219,7 @@ impl Rectangle { ... } -今、比較して等しさを確かめることのできる型という観点から長方形を定義できました。 +今、比較して等しさを確かめることのできる型について長方形を定義できました。 [PartialEq]: ../core/cmp/trait.PartialEq.html @@ -238,7 +238,7 @@ to know more about [operator traits][operators-and-overloading]. --> -ここまでで、構造体へトレイトの実装を追加することだけを説明してきましたが、あらゆる型についてトレイトを実装することができます。技術的には、 `i32` のための `HasArea` を実装することも _できなくはない_ です。 +ここまでで、構造体へトレイトの実装を追加することだけを説明してきましたが、あらゆる型についてトレイトを実装することもできます。技術的には、 `i32` のための `HasArea` を実装することも _できなくはない_ です。 ```rust trait HasArea { @@ -258,7 +258,7 @@ impl HasArea for i32 { -しかし例え可能であったとしても、そのようなプリミティブ型のメソッドを実装するのは拙い手法だと考えられています。 +しかし例え可能であったとしても、そのようなプリミティブ型のメソッドを実装するのは適切でない手法だと考えられています。 @@ -297,7 +297,8 @@ use std::io::Write; let mut f = std::fs::File::open("foo.txt").expect("Couldn’t open foo.txt"); let buf = b"whatever"; let result = f.write(buf); -# result.unwrap(); // ignore the error +# // result.unwrap(); // ignore the error +# // result.unwrap(); // エラーを無視します。 ``` @@ -317,7 +318,7 @@ not, because neither the trait nor the type are in our code. --> -トレイトに関して最後に1つ。トレイトによって束縛されたジェネリック関数は「モノモーフィゼーション」(monomorphization)(mono:単一の、morph:様相)されるため、静的ディスパッチが行われます。一体どういう意味でしょうか?詳細については、[トレイトオブジェクト][to]の章をチェックしてください。 +トレイトに関して最後に1つ。トレイト境界が設定されたジェネリック関数は「モノモーフィゼーション」(monomorphization)(mono:単一の、morph:様相)されるため、静的ディスパッチが行われます。一体どういう意味でしょうか?詳細については、 [トレイトオブジェクト][to] の章をチェックしてください。 [to]: trait-objects.html @@ -325,7 +326,7 @@ What’s that mean? Check out the chapter on [trait objects][to] for more detail # 複数のトレイト境界 -トレイトでジェネリックな型パラメータに境界が与えられることを見てきました。 +トレイトによってジェネリックな型パラメータに境界が与えられることを見てきました。 ```rust fn foo(x: T) { @@ -372,7 +373,7 @@ far right. The bounds are getting in the way. --> -Rustは「`where` 節」と呼ばれる解決策を持っています。 +Rustは「 `where` 節」と呼ばれる解決策を持っています。 ```rust use std::fmt::Debug; @@ -399,7 +400,7 @@ fn main() { All you need to do is leave off the bounds when defining your type parameters, and then add `where` after the parameter list. For longer lists, whitespace can be added: --> -`foo()` は先程見せたままの構文で、 `bar()` は `where` 節を用いています。あなたに必要なのは型パラメータの定義時に境界の設定をやめ、引数リストの後ろに `where` を追加することだけです。長いリストであれば、空白を加えることもできます。 +`foo()` は先程見せたままの構文で、 `bar()` は `where` 節を用いています。あなたに必要なのは型パラメータを定義する際に境界の設定をせず、引数リストの後ろに `where` を追加することだけです。長いリストであれば、空白を加えることもできます。 ```rust use std::fmt::Debug; @@ -449,7 +450,7 @@ fn inverse() -> T on the left-hand side not only of type parameters `T`, but also of types (`i32` in this case). In this example, `i32` must implement `ConvertTo`. Rather than defining what `i32` is (since that's obvious), the `where` clause here constrains `T`. --> -ここでは `where` 節の追加機能を披露しています。この節は左辺に型パラメータ `T` だけでなく具体的な型(このケースでは `i32` )を指定できます。この例だと、 `i32` は `ConvertTo` を実装していなければなりません。(それは明らかですから)ここの `where` 節は `i32` が何であるかの定義というより、 `T` の制約といえるでしょう。 +ここでは `where` 節の追加機能を披露しています。この節は左辺に型パラメータ `T` だけでなく具体的な型(このケースでは `i32` )を指定できます。この例だと、 `i32` は `ConvertTo` を実装していなければなりません。(それは明らかですから)ここの `where` 節は `i32` が何であるか定義しているというよりも、 `T` に対して制約を設定しているといえるでしょう。 # デフォルトメソッド @@ -466,7 +467,7 @@ trait Foo { ``` -`Foo` トレイトの実装者は `is_valid()` を実装する必要がありますが、デフォルトの動作が加えられている `is_invalid()` にはその必要がありません。 +`Foo` トレイトの実装者は `is_valid()` を実装する必要がありますが、デフォルトの動作が加えられている `is_invalid()` には必要ありません。 ```rust # trait Foo { @@ -511,7 +512,7 @@ assert!(over.is_invalid()); // 「Called OverrideDefault.is_invalid!」を表示 # 継承 -時々、トレイトの実装に他のトレイトの実装が必要になることがあります。 +時々、1つのトレイトの実装に他のトレイトの実装が必要になります。 ```rust trait Foo { @@ -523,8 +524,8 @@ trait FooBar : Foo { } ``` -Implementors of `FooBar` must also implement `Foo`, like this: -`FooBar` の実装者は以下のように `Foo` も実装しなければなりません。 + +`FooBar` の実装者は `Foo` も実装しなければなりません。以下のようになります。 ```rust # trait Foo { From 2073b953318a8e1a1834b5444500f0fa1e9954b8 Mon Sep 17 00:00:00 2001 From: Nnwww Date: Sun, 7 Feb 2016 18:20:35 +0900 Subject: [PATCH 5/7] reflect reviews --- 1.6/ja/book/traits.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/1.6/ja/book/traits.md b/1.6/ja/book/traits.md index 6c3ac739..6ea31f53 100644 --- a/1.6/ja/book/traits.md +++ b/1.6/ja/book/traits.md @@ -28,7 +28,7 @@ impl Circle { 始めにトレイトをメソッドのシグネチャと共に定義し、続いてある型のためにトレイトを実装するという流れを除けばトレイトはメソッド構文に似ています。 -この例では、 `Circle` のために `HasArea` トレイトを実装しています。 +この例では、 `Circle` に `HasArea` トレイトを実装しています。 ```rust struct Circle { @@ -178,7 +178,7 @@ error: the trait `HasArea` is not implemented for the type `_` [E0277] -ジェネリック構造体もトレイト境界による恩恵を受けることができます。あなたがしなければならないのは型パラメータを宣言する際に境界を追加することだけです。以下が新しい型 `Rectangle` とそのメソッド `is_square()` です。 +ジェネリック構造体もトレイト境界による恩恵を受けることができます。型パラメータを宣言する際に境界を追加するだけで良いのです。以下が新しい型 `Rectangle` とそのメソッド `is_square()` です。 ```rust struct Rectangle { @@ -219,7 +219,7 @@ impl Rectangle { ... } -今、比較して等しさを確かめることのできる型について長方形を定義できました。 +これで、長方形を等値性の比較できる任意の型として定義できました。 [PartialEq]: ../core/cmp/trait.PartialEq.html @@ -228,7 +228,7 @@ precision—really, objects of pretty much any type—as long as they can be compared for equality. Could we do the same for our `HasArea` structs, `Square` and `Circle`? Yes, but they need multiplication, and to work with that we need to know more about [operator traits][operators-and-overloading]. --> -上記の例では任意の精度を許容する `Rectangle` 構造体を新たに定義しました-実のところ、比較して等しさを確かめることのできるほぼ全ての型に対して利用可能なオブジェクトです。同じことを `Square` や `Circle` のような `HasArea` を実装する構造体に対してできるでしょうか?可能では有りますが乗算が必要になるため、それをするには [オペレータトレイト][operators-and-overloading] についてより詳しく知らなければなりません。 +上記の例では任意の精度の数値を受け入れる `Rectangle` 構造体を新たに定義しました-実は、等値性を比較できるほぼ全ての型に対して利用可能なオブジェクトです。同じことを `Square` や `Circle` のような `HasArea` を実装する構造体に対してできるでしょうか?可能では有りますが乗算が必要になるため、それをするには [オペレータトレイト][operators-and-overloading] についてより詳しく知らなければなりません。 [operators-and-overloading]: operators-and-overloading.html @@ -238,7 +238,7 @@ to know more about [operator traits][operators-and-overloading]. --> -ここまでで、構造体へトレイトの実装を追加することだけを説明してきましたが、あらゆる型についてトレイトを実装することもできます。技術的には、 `i32` のための `HasArea` を実装することも _できなくはない_ です。 +ここまでで、構造体へトレイトの実装を追加することだけを説明してきましたが、あらゆる型についてトレイトを実装することもできます。技術的には、 `i32` に `HasArea` を実装することも _できなくはない_ です。 ```rust trait HasArea { @@ -266,13 +266,13 @@ that if the trait isn’t defined in your scope, it doesn’t apply. Here’s an example: the standard library provides a [`Write`][write] trait which adds extra functionality to `File`s, for doing file I/O. By default, a `File` won’t have its methods: --> -ここまでくると何でもありなように思えますが、手が負えなくなることを防ぐためにトレイトの実装周りには2つの制限が設けられています。第1に、あなたのスコープ内で定義されていないトレイトは適用されません。例えば、標準ライブラリは `File` にI/O機能を追加するための `Write` トレイトを提供しています。デフォルトでは、 `File` はそのメソッドを持っていません。 +ここまでくると世紀末感漂いますが、手が負えなくなることを防ぐためにトレイトの実装周りには2つの制限が設けられています。第1に、あなたのスコープ内で定義されていないトレイトは適用されません。例えば、標準ライブラリは `File` にI/O機能を追加するための `Write` トレイトを提供しています。デフォルトでは、 `File` は `Writes` で定義されるメソッド群を持っていません。 [write]: ../std/io/trait.Write.html ```rust,ignore let mut f = std::fs::File::open("foo.txt").expect("Couldn’t open foo.txt"); -# let buf = b"whatever"; // byte string literal. buf: &[u8; 8] +# // let buf = b"whatever"; // byte string literal. buf: &[u8; 8] let buf = b"whatever"; // buf: &[u8; 8] はバイト文字列リテラルです。 let result = f.write(buf); # // result.unwrap(); // ignore the error @@ -400,7 +400,7 @@ fn main() { All you need to do is leave off the bounds when defining your type parameters, and then add `where` after the parameter list. For longer lists, whitespace can be added: --> -`foo()` は先程見せたままの構文で、 `bar()` は `where` 節を用いています。あなたに必要なのは型パラメータを定義する際に境界の設定をせず、引数リストの後ろに `where` を追加することだけです。長いリストであれば、空白を加えることもできます。 +`foo()` は先程見せたままの構文で、 `bar()` は `where` 節を用いています。型パラメータを定義する際に境界の設定をせず、引数リストの後ろに `where` を追加するだけで良いのです。長いリストであれば、空白を加えることもできます。 ```rust use std::fmt::Debug; @@ -416,7 +416,7 @@ fn bar(x: T, y: K) ``` -この柔軟性により複雑な状況であっても明瞭さを付加することができます。 +この柔軟性により複雑な状況であっても可読性を改善できます。 また、`where` は基本の構文よりも強力です。例えば、 From 027782312827f03bbfd534c955ac1c3631142c83 Mon Sep 17 00:00:00 2001 From: Nnwww Date: Mon, 8 Feb 2016 20:45:03 +0900 Subject: [PATCH 6/7] =?UTF-8?q?translate=20'deriving'=20to=20=E3=80=8C?= =?UTF-8?q?=E5=B0=8E=E5=87=BA=E3=80=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1.6/ja/book/traits.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/1.6/ja/book/traits.md b/1.6/ja/book/traits.md index 6ea31f53..4749417d 100644 --- a/1.6/ja/book/traits.md +++ b/1.6/ja/book/traits.md @@ -553,7 +553,7 @@ error: the trait `main::Foo` is not implemented for the type `main::Baz` [E0277] ``` -# Deriving +# 導出 -ただし、derivingは以下の特定のトレイトに制限されています。 +ただし、導出は以下の特定のトレイトに制限されています。 - [`Clone`](../core/clone/trait.Clone.html) - [`Copy`](../core/marker/trait.Copy.html) From a2ed7f3b96267dce2f7a8d4f0a7259a4da18b6e3 Mon Sep 17 00:00:00 2001 From: Nnwww Date: Mon, 8 Feb 2016 20:47:35 +0900 Subject: [PATCH 7/7] modify 'deriving' to 'derive' --- 1.6/ja/book/traits.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/1.6/ja/book/traits.md b/1.6/ja/book/traits.md index 4749417d..e60916fb 100644 --- a/1.6/ja/book/traits.md +++ b/1.6/ja/book/traits.md @@ -553,7 +553,7 @@ error: the trait `main::Foo` is not implemented for the type `main::Baz` [E0277] ``` -# 導出 +# Derive -ただし、導出は以下の特定のトレイトに制限されています。 +ただし、deriveは以下の特定のトレイトに制限されています。 - [`Clone`](../core/clone/trait.Clone.html) - [`Copy`](../core/marker/trait.Copy.html)