@@ -469,7 +469,7 @@ msgstr "デフォルトメソッド"
469
469
470
470
#: src/SUMMARY.md:144 src/traits/trait-bounds.md:1
471
471
msgid "Trait Bounds"
472
- msgstr "トレイト境界 "
472
+ msgstr "トレイト制約 "
473
473
474
474
#: src/SUMMARY.md:145
475
475
msgid "impl Trait"
@@ -7611,6 +7611,8 @@ msgstr ""
7611
7611
msgid ""
7612
7612
"Rust lets you abstract over types with traits. They're similar to interfaces:"
7613
7613
msgstr ""
7614
+ "Rustでは、型に関しての抽象化をトレイトを用いて行うことができます。トレイトは"
7615
+ "インターフェースに似ています:"
7614
7616
7615
7617
#: src/traits.md:7 src/traits/trait-objects.md:7
7616
7618
msgid "// No name needed, cats won't respond anyway.\n"
@@ -7631,20 +7633,80 @@ msgstr ""
7631
7633
#: src/traits.md:27 src/traits/trait-objects.md:24
7632
7634
msgid "\"Fido\""
7633
7635
msgstr ""
7636
+ "```rust,editable\n"
7637
+ "struct Dog { name: String, age: i8 }\n"
7638
+ "struct Cat { lives: i8 } // 猫に名前は必要ありません。どのみち猫は名前に反応"
7639
+ "しないからです。\n"
7640
+ "\n"
7641
+ "trait Pet {\n"
7642
+ " fn talk(&self) -> String;\n"
7643
+ "}\n"
7644
+ "\n"
7645
+ "impl Pet for Dog {\n"
7646
+ " fn talk(&self) -> String { format!(\"Woof, my name is {}!\", self."
7647
+ "name) }\n"
7648
+ "}\n"
7649
+ "\n"
7650
+ "impl Pet for Cat {\n"
7651
+ " fn talk(&self) -> String { String::from(\"Miau!\") }\n"
7652
+ "}\n"
7653
+ "\n"
7654
+ "fn greet<P: Pet>(pet: &P) {\n"
7655
+ " println!(\"Oh you're a cutie! What's your name? {}\", pet.talk());\n"
7656
+ "}\n"
7657
+ "\n"
7658
+ "fn main() {\n"
7659
+ " let captain_floof = Cat { lives: 9 };\n"
7660
+ " let fido = Dog { name: String::from(\"Fido\"), age: 5 };\n"
7661
+ "\n"
7662
+ " greet(&captain_floof);\n"
7663
+ " greet(&fido);\n"
7664
+ "}\n"
7665
+ "```"
7634
7666
7635
7667
#: src/traits/trait-objects.md:3
7636
7668
msgid ""
7637
7669
"Trait objects allow for values of different types, for instance in a "
7638
7670
"collection:"
7639
7671
msgstr ""
7672
+ "トレイトオブジェクトは異なる型の値をひとつのコレクションにまとめることを可能"
7673
+ "にします:"
7640
7674
7641
7675
#: src/traits/trait-objects.md:27
7642
7676
msgid "\"Hello, who are you? {}\""
7643
7677
msgstr ""
7678
+ "```rust,editable\n"
7679
+ "struct Dog { name: String, age: i8 }\n"
7680
+ "struct Cat { lives: i8 } // 猫に名前は必要ありません。どのみち猫は名前に反応"
7681
+ "しないからです。\n"
7682
+ "\n"
7683
+ "trait Pet {\n"
7684
+ " fn talk(&self) -> String;\n"
7685
+ "}\n"
7686
+ "\n"
7687
+ "impl Pet for Dog {\n"
7688
+ " fn talk(&self) -> String { format!(\"Woof, my name is {}!\", self."
7689
+ "name) }\n"
7690
+ "}\n"
7691
+ "\n"
7692
+ "impl Pet for Cat {\n"
7693
+ " fn talk(&self) -> String { String::from(\"Miau!\") }\n"
7694
+ "}\n"
7695
+ "\n"
7696
+ "fn main() {\n"
7697
+ " let pets: Vec<Box<dyn Pet>> = vec![\n"
7698
+ " Box::new(Cat { lives: 9 }),\n"
7699
+ " Box::new(Dog { name: String::from(\"Fido\"), age: 5 }),\n"
7700
+ " ];\n"
7701
+ " for pet in pets {\n"
7702
+ " println!(\"Hello, who are you? {}\", pet.talk());\n"
7703
+ " }\n"
7704
+ "}\n"
7705
+ "```"
7644
7706
7645
7707
#: src/traits/trait-objects.md:32
7646
7708
msgid "Memory layout after allocating `pets`:"
7647
- msgstr ""
7709
+ msgstr "`pets`を割り当てた後のメモリレイアウト: "
7648
7710
7649
7711
#: src/traits/trait-objects.md:34
7650
7712
msgid ""
@@ -7712,18 +7774,24 @@ msgid ""
7712
7774
"Types that implement a given trait may be of different sizes. This makes it "
7713
7775
"impossible to have things like `Vec<dyn Pet>` in the example above."
7714
7776
msgstr ""
7777
+ "同じトレイトを実装する型であってもそのサイズは異なることがあります。そのた"
7778
+ "め、上の例でVec<dyn Pet>と書くことはできません。"
7715
7779
7716
7780
#: src/traits/trait-objects.md:70
7717
7781
msgid ""
7718
7782
"`dyn Pet` is a way to tell the compiler about a dynamically sized type that "
7719
7783
"implements `Pet`."
7720
7784
msgstr ""
7785
+ "`dyn Pet` はコンパイラに、この型が`Pet`トレイトを実装する動的なサイズの型であ"
7786
+ "ることを伝えます。"
7721
7787
7722
7788
#: src/traits/trait-objects.md:72
7723
7789
msgid ""
7724
7790
"In the example, `pets` is allocated on the stack and the vector data is on "
7725
7791
"the heap. The two vector elements are _fat pointers_:"
7726
7792
msgstr ""
7793
+ "上の例では `pets` はスタックに確保され、ベクターのデータはヒープ上にありま"
7794
+ "す。二つのベクターの要素は _ファットポインタ_ です:"
7727
7795
7728
7796
#: src/traits/trait-objects.md:74
7729
7797
msgid ""
@@ -7732,16 +7800,26 @@ msgid ""
7732
7800
"wikipedia.org/wiki/Virtual_method_table) (vtable) for the `Pet` "
7733
7801
"implementation of that particular object."
7734
7802
msgstr ""
7803
+ "ファットポインタはdouble-widthポインタです。これは二つの要素からなります:実"
7804
+ "際のオブジェクトへのポインタと、そのオブジェクトの`Pet`の実装のための[仮想関"
7805
+ "数テーブル](https://ja.wikipedia.org/wiki/"
7806
+ "%E4%BB%AE%E6%83%B3%E9%96%A2%E6%95%B0%E3%83%86%E3%83%BC%E3%83%96%E3%83%AB) "
7807
+ "(vtable)です。"
7735
7808
7736
7809
#: src/traits/trait-objects.md:77
7737
7810
msgid ""
7738
7811
"The data for the `Dog` named Fido is the `name` and `age` fields. The `Cat` "
7739
7812
"has a `lives` field."
7740
7813
msgstr ""
7814
+ "\"Fido\"と名付けられた`Dog`のデータは`name` と `age` のフィールドに対応しま"
7815
+ "す。(訳注: \"Fido\"とはよくある犬の愛称で、日本語でいう「ポチ」のような名前"
7816
+ "です。)例の`Cat`には`lives` フィールドがあります。(訳注: ここで`Cat`が"
7817
+ "`lives`というフィールドを持ち、9で初期化しているのは\"A cat has nine lives\" "
7818
+ "—猫は9つの命を持つ—ということわざに由来します。)"
7741
7819
7742
7820
#: src/traits/trait-objects.md:79
7743
7821
msgid "Compare these outputs in the above example:"
7744
- msgstr ""
7822
+ msgstr "上の例において、下のコードによる出力結果を比べてみましょう: "
7745
7823
7746
7824
#: src/traits/trait-objects.md:81 src/traits/trait-objects.md:82
7747
7825
#: src/traits/closures.md:54
@@ -7760,10 +7838,12 @@ msgid ""
7760
7838
"Rust derive macros work by automatically generating code that implements the "
7761
7839
"specified traits for a data structure."
7762
7840
msgstr ""
7841
+ "Rustのderiveマクロは、データ構造体に対して、指定されたトレイトを実装するコー"
7842
+ "ドを自動的に生成します。"
7763
7843
7764
7844
#: src/traits/deriving-traits.md:5
7765
7845
msgid "You can let the compiler derive a number of traits as follows:"
7766
- msgstr ""
7846
+ msgstr "コンパイラには、以下のような多くのトレイトを導出させることができます: "
7767
7847
7768
7848
#: src/traits/deriving-traits.md:18
7769
7849
msgid "\"Is {:?}\\nequal to {:?}?\\nThe answer is {}!\""
@@ -7782,6 +7862,7 @@ msgstr ""
7782
7862
#: src/traits/default-methods.md:3
7783
7863
msgid "Traits can implement behavior in terms of other trait methods:"
7784
7864
msgstr ""
7865
+ "トレイトでは、別のトレイトメソッドを用いて挙動を定義することが可能です:"
7785
7866
7786
7867
#: src/traits/default-methods.md:25
7787
7868
msgid "\"{a:?} equals {b:?}: {}\""
@@ -7797,34 +7878,46 @@ msgid ""
7797
7878
"are required to implement themselves. Methods with default implementations "
7798
7879
"can rely on required methods."
7799
7880
msgstr ""
7881
+ "トレイトは予め実装された(デフォルトの)メソッドと、ユーザが自身で実装する必"
7882
+ "要のあるメソッドを指定することができます。デフォルトの実装のあるメソッドは、"
7883
+ "その定義を実装必須のメソットに依存することができます。"
7800
7884
7801
7885
#: src/traits/default-methods.md:35
7802
7886
msgid "Move method `not_equals` to a new trait `NotEquals`."
7803
7887
msgstr ""
7888
+ "メソッド `not_equals` を新しいトレイト `NotEquals` に移してみましょう。"
7804
7889
7805
7890
#: src/traits/default-methods.md:37
7806
7891
msgid "Make `Equals` a super trait for `NotEquals`."
7807
- msgstr ""
7892
+ msgstr "`Equals` を `NotEquals` のスーパートレイトにしてみましょう。 "
7808
7893
7809
7894
#: src/traits/default-methods.md:46
7810
7895
msgid "Provide a blanket implementation of `NotEquals` for `Equals`."
7811
- msgstr ""
7896
+ msgstr "`Equals`に対する`NotEquals`のブランケット実装を示してみましょう。 "
7812
7897
7813
7898
#: src/traits/default-methods.md:58
7814
7899
msgid ""
7815
7900
"With the blanket implementation, you no longer need `Equals` as a super "
7816
7901
"trait for `NotEqual`."
7817
7902
msgstr ""
7903
+ "ブランケット実装を用いれば、`Equals` を`NotEqual`のスーパートレイトとする必要"
7904
+ "はなくなります。"
7818
7905
7819
7906
#: src/traits/trait-bounds.md:3
7820
7907
msgid ""
7821
7908
"When working with generics, you often want to require the types to implement "
7822
7909
"some trait, so that you can call this trait's methods."
7823
7910
msgstr ""
7911
+ "ジェネリクスを用いるとき、あるトレイトのメソッドを呼び出せるように、型がその"
7912
+ "トレイトを実装していることを要求したいことがよくあります。(脚注:本教材では"
7913
+ "\"Trait bounds\"を「トレイト制約」と翻訳しましたが、Rustの日本語翻訳コミュニ"
7914
+ "ティでは「トレイト境界」と呼ぶ流派もあり、どちらの翻訳を採用するかについては"
7915
+ "[議論がなされています](https://github.com/rust-lang-ja/book-ja/"
7916
+ "issues/172)。)"
7824
7917
7825
7918
#: src/traits/trait-bounds.md:6
7826
7919
msgid "You can do this with `T: Trait` or `impl Trait`:"
7827
- msgstr ""
7920
+ msgstr "そうしたことは`T: Trait` や `impl Trait`を用いて行えます: "
7828
7921
7829
7922
#: src/traits/trait-bounds.md:12
7830
7923
msgid ""
@@ -7847,24 +7940,54 @@ msgstr ""
7847
7940
#: src/traits/trait-bounds.md:29
7848
7941
msgid "\"{many_more}\""
7849
7942
msgstr ""
7943
+ "```rust,editable\n"
7944
+ "fn duplicate<T: Clone>(a: T) -> (T, T) {\n"
7945
+ " (a.clone(), a.clone())\n"
7946
+ "}\n"
7947
+ "\n"
7948
+ "// 以下の糖衣構文です:\n"
7949
+ "// fn add_42_millions<T: Into<i32>>(x: T) -> i32 {\n"
7950
+ "fn add_42_millions(x: impl Into<i32>) -> i32 {\n"
7951
+ " x.into() + 42_000_000\n"
7952
+ "}\n"
7953
+ "\n"
7954
+ "// struct NotClonable;\n"
7955
+ "\n"
7956
+ "fn main() {\n"
7957
+ " let foo = String::from(\"foo\");\n"
7958
+ " let pair = duplicate(foo);\n"
7959
+ " println!(\"{pair:?}\");\n"
7960
+ "\n"
7961
+ " let many = add_42_millions(42_i8);\n"
7962
+ " println!(\"{many}\");\n"
7963
+ " let many_more = add_42_millions(10_000_000);\n"
7964
+ " println!(\"{many_more}\");\n"
7965
+ "}\n"
7966
+ "```"
7850
7967
7851
7968
#: src/traits/trait-bounds.md:35
7852
7969
msgid "Show a `where` clause, students will encounter it when reading code."
7853
7970
msgstr ""
7971
+ "`where` 節の使い方を示しましょう。受講生はコードを読んでいるときに、この"
7972
+ "`where`節に遭遇します。"
7854
7973
7855
7974
#: src/traits/trait-bounds.md:46
7856
7975
msgid "It declutters the function signature if you have many parameters."
7857
7976
msgstr ""
7977
+ "たくさんのパラメタがある場合に、`where`節は関数のシグネチャを整理整頓してくれ"
7978
+ "ます。"
7858
7979
7859
7980
#: src/traits/trait-bounds.md:47
7860
7981
msgid "It has additional features making it more powerful."
7861
- msgstr ""
7982
+ msgstr "`where`節には更に強力な機能があります。 "
7862
7983
7863
7984
#: src/traits/trait-bounds.md:48
7864
7985
msgid ""
7865
7986
"If someone asks, the extra feature is that the type on the left of \":\" can "
7866
7987
"be arbitrary, like `Option<T>`."
7867
7988
msgstr ""
7989
+ "誰かに聞かれた場合で良いですが、その機能というのは、\":\" の左側には "
7990
+ "`Option<T>` のように任意の型を表現できるというものです。"
7868
7991
7869
7992
#: src/traits/impl-trait.md:1
7870
7993
msgid "`impl Trait`"
@@ -7875,28 +7998,35 @@ msgid ""
7875
7998
"Similar to trait bounds, an `impl Trait` syntax can be used in function "
7876
7999
"arguments and return values:"
7877
8000
msgstr ""
8001
+ "トレイト境界と似たように、構文 `impl Trait`は関数の引数と返り値においてのみ利"
8002
+ "用可能です:"
7878
8003
7879
8004
#: src/traits/impl-trait.md:19
7880
8005
msgid "`impl Trait` allows you to work with types which you cannot name."
7881
- msgstr ""
8006
+ msgstr "`impl Trait`を用いれば、型名を明示せずに型を限定することができます。 "
7882
8007
7883
8008
#: src/traits/impl-trait.md:23
7884
8009
msgid ""
7885
8010
"The meaning of `impl Trait` is a bit different in the different positions."
7886
- msgstr ""
8011
+ msgstr "`impl Trait`の意味は、位置によって少し異なります。 "
7887
8012
7888
8013
#: src/traits/impl-trait.md:25
7889
8014
msgid ""
7890
8015
"For a parameter, `impl Trait` is like an anonymous generic parameter with a "
7891
8016
"trait bound."
7892
8017
msgstr ""
8018
+ "パラメタに対しては、`impl Trait`は、トレイト境界を持つ匿名のジェネリックパラ"
8019
+ "メタのようなものです。"
7893
8020
7894
8021
#: src/traits/impl-trait.md:27
7895
8022
msgid ""
7896
8023
"For a return type, it means that the return type is some concrete type that "
7897
8024
"implements the trait, without naming the type. This can be useful when you "
7898
8025
"don't want to expose the concrete type in a public API."
7899
8026
msgstr ""
8027
+ "返り値の型に用いる場合は、特定のトレイトを実装する何らかの具象型を返すが、具"
8028
+ "体的な型名は明示しないということを意味します。このことは公開されるAPIに具象型"
8029
+ "を晒したくない場合に便利です。"
7900
8030
7901
8031
#: src/traits/impl-trait.md:31
7902
8032
msgid ""
@@ -7907,6 +8037,12 @@ msgid ""
7907
8037
"`let x: Vec<_> = foo.collect()` or with the turbofish, `foo.collect::"
7908
8038
"<Vec<_>>()`."
7909
8039
msgstr ""
8040
+ "返り値の位置における型推論は困難です。`impl Foo`を返す関数は、それが返す具象"
8041
+ "型はソースコードに書かれることないまま、具象型を選びます。`collect<B>() -> B`"
8042
+ "のようなジェネリック型を返す関数は、`B`を満たすどのような型でも返すことがあり"
8043
+ "ます。 また、関数の呼び出し元はそのような型を一つを選ぶ必要があるかもしれませ"
8044
+ "ん。 それは、 `let x: Vec<_> = foo.collect()`としたり、turbofishを用いて`foo."
8045
+ "collect::<Vec<_>>()`とすることで行えます。"
7910
8046
7911
8047
#: src/traits/impl-trait.md:37
7912
8048
msgid ""
@@ -7918,6 +8054,13 @@ msgid ""
7918
8054
"`format!` returns. If we wanted to do the same via `: Display` syntax, we'd "
7919
8055
"need two independent generic parameters."
7920
8056
msgstr ""
8057
+ "この例は素晴らしい例です。なぜなら、 `impl Display`を2回用いているからで"
8058
+ "す。 ここでは `impl Display` の型が同一になることを強制するものはない、という"
8059
+ "説明をするのに役立ちます。もし単一の`T: Display`を用いた場合、入力の`T`と返り"
8060
+ "値の`T`が同一の型であることが強制されてしまいます。例で示した関数ではうまくい"
8061
+ "かないでしょう。なぜなら、我々が期待する入力の型は、`format!`が返すものではお"
8062
+ "そらくないからです。もしも同じことを`: Display`の構文で行いたい場合、2つの独"
8063
+ "立したジェネリックなパラメタが必要となるでしょう。"
7921
8064
7922
8065
#: src/traits/important-traits.md:3
7923
8066
msgid ""
0 commit comments