Coder Social home page Coder Social logo

book-ja's Introduction

The Rust Programming Language

CircleCI

This repository contains the source of "The Rust Programming Language" book.

The book is available in dead-tree form from No Starch Press.

You can also read the book for free online. Please see the book as shipped with the latest stable, beta, or nightly Rust releases. Be aware that issues in those versions may have been fixed in this repository already, as those releases are updated less frequently.

See the releases to download just the code of all the code listings that appear in the book.

Requirements

Building the book requires mdBook, ideally the same version that rust-lang/rust uses in this file. To get it:

$ cargo install mdbook --vers [version-num]

Building

To build the book, type:

$ mdbook build

The output will be in the book subdirectory. To check it out, open it in your web browser.

Firefox:

$ firefox book/index.html                       # Linux
$ open -a "Firefox" book/index.html             # OS X
$ Start-Process "firefox.exe" .\book\index.html # Windows (PowerShell)
$ start firefox.exe .\book\index.html           # Windows (Cmd)

Chrome:

$ google-chrome book/index.html                 # Linux
$ open -a "Google Chrome" book/index.html       # OS X
$ Start-Process "chrome.exe" .\book\index.html  # Windows (PowerShell)
$ start chrome.exe .\book\index.html            # Windows (Cmd)

To run the tests:

$ mdbook test

Contributing

We'd love your help! Please see CONTRIBUTING.md to learn about the kinds of contributions we're looking for.

Translations

We'd love help translating the book! See the Translations label to join in efforts that are currently in progress. Open a new issue to start working on a new language! We're waiting on mdbook support for multiple languages before we merge any in, but feel free to start!

Spellchecking

To scan source files for spelling errors, you can use the spellcheck.sh script. It needs a dictionary of valid words, which is provided in dictionary.txt. If the script produces a false positive (say, you used word BTreeMap which the script considers invalid), you need to add this word to dictionary.txt (keep the sorted order for consistency).

book-ja's People

Contributors

aaaxx avatar awaitlink avatar bmusin avatar bn-e avatar carols10cents avatar chenl avatar clemensw avatar davidde avatar dnaeon avatar dralley avatar elahn avatar frewsxcv avatar grantmoyer avatar gypsydave5 avatar jightuse avatar josephtlyons avatar koic avatar lancelafontaine avatar mimoo avatar nojima avatar outkaj avatar pduzinki avatar scivola avatar sebras avatar spastorino avatar steveklabnik avatar swnakamura avatar tatsuya6502 avatar toku-sa-n avatar unhumbleben avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

book-ja's Issues

コンパイラのライフタイム推論に関する文が読みにくい

「10.3. ライフタイムで参照を検証する」の以下の箇所について申し上げます:
https://github.com/rust-lang-ja/book-ja/blame/second-edition-ja/second-edition/src/ch10-03-lifetime-syntax.md#L842-852

この文の、特に以下の文が特に読みにくいものとなっています:

この場合、推論ではなく、コンパイラは、参照がお互いにどう関係するかを指定するライフタイム注釈を追記することで、 解決できるエラーを与えます。

対応する英語原文は以下のとおりです:

In this case, instead of guessing, the compiler will give you an error that you can resolve by adding the lifetime annotations that specify how the references relate to each other.

文が読みにくい理由としては以下のような点が挙げられると思います:

  • instead of guessing が文に唐突に「推論ではなく」として現れている
  • 「追記する」と「解決できる」の主語がわかりにくい(youを極力省略した結果余計にわかりにくくなっている)

特に思ったのですが、この文の1つ目の that は、本来は非制限用法で書かれていたのではないでしょうか? というのも、制限用法として解釈すると「解決できるエラー(だけ)を与える」と読み取られるからです。Rust初心者なので自信はないのですが、コンパイラが解決できないからユーザーに解決を迫るのですよね。それを踏まえると、この文はこのように解釈されると思いますが、正しいでしょうか?

In this case, instead of guessing, the compiler will give you an error, which you can resolve by adding the lifetime annotations that specify how the references relate to each other.

この場合コンパイラは、それらを推測するのではなくエラーを与えます。これらは、参照がお互いにどう関係するかを指定するライフタイム注釈を追記することで解決できます。

ch11-01のアップデート(2018 Edition)

Chapter 11-01の内容を最新版にアップデートする。2018 Edition対応として内容が追加されている。

Chapter 11 has a new section titled “Using Result<T, E> in Tests” that shows how to write tests that use the ? operator.

14.3 Cargoのワークスペースの解説のオプションのミス?

Cargoのワークスペースのページのワークスペース内に2番目のクレートを作成する
で、

$ cargo new add-one
     Created library `add-one` project

とありますが、ライブラリ を作るときは--libは付けなくても良いんでしょうか?

実際試してたらバイナリクレートができたのと、英語版ではオプションが付いてたので、一応Issue立てました。

4章スライスのサンプルコードでエラーが発生するとあるが、発生しないコードがある

詳細

https://github.com/rust-lang-ja/book-ja/blob/second-edition-ja/second-edition/src/ch04-03-slices.md
にて

fn main() {
    let mut s = String::from("hello world");

    let word = first_word(&s);

    s.clear(); // error!    (エラー!)
}

でコンパイルエラーが発生するとあるが、エラーが発生しません。
原文を確認すると

fn main() {
    let mut s = String::from("hello world");

    let word = first_word(&s);

    s.clear(); // error!    (エラー!)
    println!("the first word is: {}", word);
}

でエラーが発生するようになります。

環境

rustc -V; cargo --version                                                                                                                                                                                                                      
rustc 1.41.0 (5e1a79984 2020-01-27)
cargo 1.41.0 (626f0f40e 2019-12-03)

こちら問題なければ一行追加だけなのでPR作成も一緒に行わせていただきますが、よろしいでしょうか?

ch04-03のアップデート

ch04-03の内容を最新版にアップデートする。

  • 対象ファイル:master-jaブランチの ch04-03-slices.md
  • Second Editionでは、コンパイルエラーが起きるべきところで起こらないという報告があり、該当のコードだけは既に修正してある(#63

翻訳手順については 今後ドキュメント化する予定 です。それまでの間、手順についてはSlack rust-jpのtranslationチャンネルで質問してください。登録URL

ch05-01 について

https://doc.rust-jp.rs/book-ja/ch05-01-defining-structs.html

タプル構造体は、タプル全体に名前をつけ、 そのタプルを他のタプルとは異なる型にしたい場合に有用ですが、普通の構造体のように各フィールド名を与えるのは、 冗長、または余計になるでしょう。

とありますが,意味が取りづらく思います。
ぼうっと読むと「タプル構造体は有用だがフィールド名は余計」というふうに読めてしまいます。
原文は

Tuple structs are useful when you want to give the whole tuple a name and make the tuple be a different type from other tuples, and naming each field as in a regular struct would be verbose or redundant.

とあり,どんな場合に useful なのか,を表す when 節のなかに

  • 全体には名前を与えたい
  • フィールドに名前を与えるのは余計

という二つのことが並列にあるのだと思います。
(訳文の改善案の提示まではできないので PR でなく issue にしました)

「トレイト境界」という訳語

Trait bound という用語に「トレイト境界」という訳語が宛てられていますが、(専門用語として確立しているのでなければ)あまり達意の訳とはいいがたい気がします。

私見で恐縮ですが、英語で "bound" といった時は、例えば敷地の境界線やベン図で集合を区切る線など、ある一定の広がりを持つものを想像しながら、それが属性として持つ「外縁」としてイメージされると思います。それに対して、日本語で「境界」という時は、「線」の意味が中心で、それが両側で何かと何かを分けているようなものというふうに想像されます。
(前者は「犯人」で後者は「犯罪者」に近いということもできます。「犯人を逮捕する」と「犯罪者を逮捕する」では想像する情景が違うと思います。)

単体で使われている時はそういうものなのかな、と思う程度ですが、他の概念との関連で「~に対するトレイト境界」とか「トレイト境界を含む~」などの場面で現れると、「トレイトを『分割』している?」とか「何かの『境界』をまたいでいる?」みたいに変な想像が働いてしまって、混乱を生みやすいと思います。

他の用語と紛らわしくならないのであれば、「境界」の代わりに例えば限界範囲などのほうがいい気がしますがいかがでしょうか。

付録Aのアップデート(2018 Edition)

付録Aの内容を最新版にアップデートする。2018 Edition対応としてキーワードが追加されている。

Appendix A, “Keywords,” also explains the new raw identifiers feature that enables code written in the 2015 Edition and the 2018 Edition to interoperate.

ch01-01のアップデート

ch01-01の内容を最新版にアップデートする。

  • 対象ファイル:master-jaブランチの ch01-01-installation.md
  • 現在の内容ではRustのインストール手順が古くなってしまっているので、早めにアップデートしたい
    • LinuxやmacOSへのrustupインストールで、curlコマンドのオプションが足りない
    • Windowsへのrustupインストールで、MSVCビルドツールのバージョンが古い

翻訳手順については 今後ドキュメント化する予定 です。それまでの間、手順についてはSlack rust-jpのtranslationチャンネルで質問してください。登録URL

ch17-02:「実行時」にコンパイラはどのメソッドを呼ぶか知る?

ch17-02
https://doc.rust-jp.rs/book-ja/ch17-02-trait-objects.html

代わりに実行時に、トレイトオブジェクト内でポインタを使用して、 コンパイラは、どのメソッドを呼ぶか知ります。

とあります。原文は

Instead, at runtime, Rust uses the pointers inside the trait object to know which method to call.

です。
原文のほうも「一体その Rust って誰だよ?」という疑問が涌いてきますが,少なくともコンパイラーが実行時に何かを知る,ということはあり得ないことだと思います。

Contributionの手順をドキュメント化する

TODO まだ書きかけです。

  • 手順の概要
    1. GH Issueで手を上げる(アサインしてもらう)
    2. PRをオープンする
    3. ...
  • 対訳表について
  • mdbook-transcheckについて
  • mdBookのバージョンについて
  • CIについて(特にartifactsページ)

ch15-02:冒頭の注釈(`MyBox<T>`と`Box<T>`の違いに関するもの)を追加する

原文では このissue によって、 章の冒頭に以下のコメントが追加されている。

Note: there’s one big difference between the MyBox<T> type we’re about to build and the real Box<T>: our version will not store its data on the heap. We are focusing this example on Deref, so where the data is actually stored is less important than the pointer-like behavior.

和訳版にもこのコメントを追加する。

用語:「control flow」は「フロー制御」でよいか?

原文の「control flow」がほとんどの箇所で「フロー制御」と訳されているようです。
(文脈をよく見ていないので自信がありませんが)これは「制御構造」のことではないのでしょうか。
あるいは「制御フロー」かもしれませんが,「フロー制御」は通信用語で全然意味が違うように思います。

ch11-01 用語:assert は「断定する」ではないのでは

ch11-01
https://doc.rust-jp.rs/book-ja/ch11-01-writing-tests.html

結果が想定通りであることを断定(以下、アサーションという)する。

とあります。原文は

Assert the results are what you expect.

です。
assert や assertion は日本語にしにくいですが,「断定」という言葉には「判断・判定」の含みがあり,訳語として合っていないと思います。
どういう訳語がよいか分かりませんが,「断定」よりは「主張」のほうが適当なのではないかと思います。

ライフタイムの解説のサンプルコード実行時に発生するエラーメッセージが説明と異なる

ライフタイムの観点で思考するで記載されているサンプルコード実行時に発生するエラーメッセージが解説されているものと異なります。

環境

% rustc -V; cargo --version
rustc 1.41.0 (5e1a79984 2020-01-27)
cargo 1.41.0 (626f0f40e 2019-12-03)

説明のコードとエラーメッセージ

// コード
fn longest<'a>(x: &str, y: &str) -> &'a str {
    // 本当に長い文字列
    let result = String::from("really long string");
    result.as_str()
}

//エラーメッセージ
error[E0597]: `result` does not live long enough
 --> src/main.rs:3:5
  |
3 |     result.as_str()
  |     ^^^^^^ does not live long enough
4 | }
  | - borrowed value only lives until here
  |
note: borrowed value must be valid for the lifeti

実際に発生するエラーメッセージ

error[E0515]: cannot return value referencing local variable `result`
  --> src/main.rs:66:3
   |
66 |   result.as_str()
   |   ------^^^^^^^^^
   |   |
   |   returns a value referencing data owned by the current function
   |   `result` is borrowed here

参考

https://doc.rust-lang.org/book/ch10-03-lifetime-syntax.html#thinking-in-terms-of-lifetimes

ch08-03 ハッシュマップの章のタイトル修正

ch08-03のタイトル "Storing Keys with Associated Values in Hash Maps" はTRPL 2のときから以下のように訳されている。

  • ハッシュマップに値に紐づいたキーを格納する

Slack rust-jpで 議論して決めた とおり、以下の訳に修正する。

  • キーとそれに紐づいた値をハッシュマップに格納する

修正対象のファイルについて

対訳表:warning ウォーニング → 警告

対訳表のwarningの訳語を、srcディレクトリー配下の本文の訳語に合わせて修正する。

  • warning ウォーニング → 警告

本リポジトリーの対訳表(TranslationTable.md)ファイルの内容は、srcディレクトリー配下にある実際の訳語と異なることが(かなり)ある。今後は本文と対訳表の内容が同じになるよう、少しずつ修正していく。本文の訳語と対訳表の訳語のどちらを採用するかは、その都度検討する。

TRPL以外の公式ドキュメントへのリンクが切れている

現在翻訳中の最新版(2018 Edition対応、master-jaブランチ)には、stdクレートやThe Unstable Bookなどの「TRPL以外」の公式ドキュメントへのリンクが含まれているページがある。それらのリンクがリンク切れになっている。

リンク切れになる理由は、URLが相対URLで記述されているため。和訳ドキュメントのサイト(doc.rust-jp.rs)ではそれらのドキュメントをホスティングしていないのでリンク切れになる。

src/ch08-00-common-collections.md
48:[collections]: ../../std/collections/index.html

調べたところ以下のMarkdownファイルに相対URLが含まれていることがわかった。これらのファイルの修正が必要となる。

  • appendix-01-keywords.md
  • ch02-00-guessing-game-tutorial.md
  • ch06-01-defining-an-enum.md
  • ch07-04-bringing-paths-into-scope-with-the-use-keyword.md
  • ch08-00-common-collections.md
  • ch11-01-writing-tests.md

上のリストを得るために使用したコマンド

$ rg -l --pcre2 '\.\./(?!listings)\S*\.html' src | sort
src/appendix-01-keywords.md
src/ch02-00-guessing-game-tutorial.md
src/ch06-01-defining-an-enum.md
src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md
src/ch08-00-common-collections.md
src/ch11-01-writing-tests.md

ch05-02 の cause errors は「エラーを発生させる」ではないのでは

https://doc.rust-jp.rs/book-ja/ch05-02-example-structs.html

これらの値を混ぜこぜにしたりしてエラーを発生させてしまうでしょう。

という文があります。
原文は

It would be easy to forget or mix up these values and cause errors

です。

この「errors」はプログラミング概念としてのエラー(コンパイルエラー,実行時エラーあるいは ResultErr など)ではなく,人間のミス・過ちのことだったりしないでしょうか?

第2版TRPL 各ページの<head>にnoindexを追記する

最新版(2018 Edition)の公開後、第2版(second edition)は全ての検索エンジンでクローリング対象外にしたい。第2版各ページの <head><meta name="robots" content="noindex"> を追記する。

ch10-02のアップデート(2018 Edition)

Chapter 10-02の内容を最新版にアップデートする。2018 Edition対応として内容が追加されている。

Chapter 10 has new sections titled “Traits as Parameters” and “Returning Types that Implement Traits” that explain the new impl Trait syntax.

validの和訳について

validを「合法な」と訳している例がたくさんあります。しかし、「合法な」という言葉だけから、「言語の文法に合致した」という意味を読み取るのは直感的ではありません。

「正しい」「文法的に正しい」「有効な」などの訳に統一し、この言葉を使わないのが適当ではないでしょうか。

ページ内のリンクが全て英語版へのものとなっている

外部サイトや別の本へのリンクが,全て英語版へのものとなっています.
例:導入の,Githubリポジトリへのリンク
  16.4の,nomiconへのリンク

直にこのリンクを修正してしまうか,訳註として日本語版へのリンクも追加するといいかもしれませんが,いかがでしょうか.

ch08-01のアップデート

ch08-01の内容を最新版にアップデートする。

  • 対象ファイル:master-jaブランチの ch08-01-vectors.md
  • Second Editionでは、コンパイルエラーが起きるべきところで起こらないという報告があり、該当のコードだけは既に修正してある(#78, #81

翻訳手順については 今後ドキュメント化する予定 です。それまでの間、手順についてはSlack rust-jpのtranslationチャンネルで質問してください。登録URL

ch19-06のアップデート(2018 Edition)

Chapter 19-06の内容を最新版にアップデートする。2018 Edition対応として内容が追加されている。

The previous Appendix D, “Macros,” has been expanded to include procedural macros and was moved to the “Macros” section in Chapter 19.

raw identifierをどう訳すか

rust 2018 editionで追加された "raw identifier"という単語は、おそらく訳語が存在しません。
ドキュメントを訳すに当たり統一した訳語を考えたいですが、いいアイデアはありますか?
自分としては、

  • 訳さない:「raw identifier」
  • 訳す:「生指定子」「直接指定子」
  • raw文字列にならって:「raw指定子」

あたりが良いと思います。

参考:
TRPL 2018におけるraw identifierの解説: https://doc.rust-lang.org/book/appendix-01-keywords.html#raw-identifiers
raw identifierのRFC: https://github.com/rust-lang/rfcs/blob/master/text/2151-raw-identifiers.md

第2版TRPLに、最新版(2018 Edition対応)への誘導リンクを追加する

最新版(2018 Edition)の公開後、第2版(second edition)の各ページに以下の内容を表示する。

注意: 最新版のドキュメントをご覧ください。この第2版ドキュメントは古くなっており、最新情報が反映されていません。リンク先のドキュメントが現在の Rust の最新のドキュメントです。

リンク先は最新版 https://doc.rust-jp.rs/book-ja/ の対応するページに設定する。

例:
https://doc.rust-jp.rs/book/second-edition/ch02-00-guessing-game-tutorial.html
  ↓
https://doc.rust-jp.rs/book-ja/ch02-00-guessing-game-tutorial.html

翻訳の修正について

https://doc.rust-jp.rs/book/second-edition/
を使ってrustの勉強をしているのですが、日本語訳に読みづらい文章・軽微な誤訳と思われる箇所をいくつか発見しており、原文と比較しながら
https://github.com/rust-lang-ja/book-ja/tree/second-edition-ja/second-edition
のソースファイルに修正をメモしています。

そこで、いくつか質問させてください:

  • これらに関するプルリクエストは受け付けていますか?
  • プルリクエストを送る場合、まずIssueを立てたほうがいいですか?
  • プルリクエストは修正箇所ごとに分けて送ったほうがいいですか?
  • 2018 editionに対応する予定は有りますか?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.