├── 2018-edition ├── Cargo.lock ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── book.toml ├── convert-quotes.sh ├── dot │ ├── trpl04-01.dot │ ├── trpl04-02.dot │ ├── trpl04-03.dot │ ├── trpl04-04.dot │ ├── trpl04-05.dot │ ├── trpl04-06.dot │ ├── trpl15-01.dot │ ├── trpl15-02.dot │ └── trpl15-03.dot ├── src │ ├── SUMMARY.md │ ├── appendix-00.md │ ├── appendix-01-keywords.md │ ├── appendix-02-operators.md │ ├── appendix-03-derivable-traits.md │ ├── appendix-04-macros.md │ ├── appendix-05-translation.md │ ├── appendix-06-newest-features.md │ ├── appendix-07-nightly-rust.md │ ├── ch00-00-introduction.md │ ├── ch01-00-getting-started.md │ ├── ch01-01-installation.md │ ├── ch01-02-hello-world.md │ ├── ch01-03-hello-cargo.md │ ├── ch02-00-guessing-game-tutorial.md │ ├── ch03-00-common-programming-concepts.md │ ├── ch03-01-variables-and-mutability.md │ ├── ch03-02-data-types.md │ ├── ch03-03-how-functions-work.md │ ├── ch03-04-comments.md │ ├── ch03-05-control-flow.md │ ├── ch04-00-understanding-ownership.md │ ├── ch04-01-what-is-ownership.md │ ├── ch04-02-references-and-borrowing.md │ ├── ch04-03-slices.md │ ├── ch05-00-structs.md │ ├── ch05-01-defining-structs.md │ ├── ch05-02-example-structs.md │ ├── ch05-03-method-syntax.md │ ├── ch06-00-enums.md │ ├── ch06-01-defining-an-enum.md │ ├── ch06-02-match.md │ ├── ch06-03-if-let.md │ ├── ch07-00-modules.md │ ├── ch07-01-mod-and-the-filesystem.md │ ├── ch07-02-controlling-visibility-with-pub.md │ ├── ch07-03-importing-names-with-use.md │ ├── ch08-00-common-collections.md │ ├── ch08-01-vectors.md │ ├── ch08-02-strings.md │ ├── ch08-03-hash-maps.md │ ├── ch09-00-error-handling.md │ ├── ch09-01-unrecoverable-errors-with-panic.md │ ├── ch09-02-recoverable-errors-with-result.md │ ├── ch09-03-to-panic-or-not-to-panic.md │ ├── ch10-00-generics.md │ ├── ch10-01-syntax.md │ ├── ch10-02-traits.md │ ├── ch10-03-lifetime-syntax.md │ ├── ch11-00-testing.md │ ├── ch11-01-writing-tests.md │ ├── ch11-02-running-tests.md │ ├── ch11-03-test-organization.md │ ├── ch12-00-an-io-project.md │ ├── ch12-01-accepting-command-line-arguments.md │ ├── ch12-02-reading-a-file.md │ ├── ch12-03-improving-error-handling-and-modularity.md │ ├── ch12-04-testing-the-librarys-functionality.md │ ├── ch12-05-working-with-environment-variables.md │ ├── ch12-06-writing-to-stderr-instead-of-stdout.md │ ├── ch13-00-functional-features.md │ ├── ch13-01-closures.md │ ├── ch13-02-iterators.md │ ├── ch13-03-improving-our-io-project.md │ ├── ch13-04-performance.md │ ├── ch14-00-more-about-cargo.md │ ├── ch14-01-release-profiles.md │ ├── ch14-02-publishing-to-crates-io.md │ ├── ch14-03-cargo-workspaces.md │ ├── ch14-04-installing-binaries.md │ ├── ch14-05-extending-cargo.md │ ├── ch15-00-smart-pointers.md │ ├── ch15-01-box.md │ ├── ch15-02-deref.md │ ├── ch15-03-drop.md │ ├── ch15-04-rc.md │ ├── ch15-05-interior-mutability.md │ ├── ch15-06-reference-cycles.md │ ├── ch16-00-concurrency.md │ ├── ch16-01-threads.md │ ├── ch16-02-message-passing.md │ ├── ch16-03-shared-state.md │ ├── ch16-04-extensible-concurrency-sync-and-send.md │ ├── ch17-00-oop.md │ ├── ch17-01-what-is-oo.md │ ├── ch17-02-trait-objects.md │ ├── ch17-03-oo-design-patterns.md │ ├── ch18-00-patterns.md │ ├── ch18-01-all-the-places-for-patterns.md │ ├── ch18-02-refutability.md │ ├── ch18-03-pattern-syntax.md │ ├── ch19-00-advanced-features.md │ ├── ch19-01-unsafe-rust.md │ ├── ch19-02-advanced-lifetimes.md │ ├── ch19-03-advanced-traits.md │ ├── ch19-04-advanced-types.md │ ├── ch19-05-advanced-functions-and-closures.md │ ├── ch20-00-final-project-a-web-server.md │ ├── ch20-01-single-threaded.md │ ├── ch20-02-multithreaded.md │ ├── ch20-03-graceful-shutdown-and-cleanup.md │ ├── foreword.md │ └── img │ │ ├── trpl04-01.svg │ │ ├── trpl04-02.svg │ │ ├── trpl04-03.svg │ │ ├── trpl04-04.svg │ │ ├── trpl04-05.svg │ │ ├── trpl04-06.svg │ │ ├── trpl14-01.png │ │ ├── trpl14-02.png │ │ ├── trpl14-03.png │ │ ├── trpl14-04.png │ │ ├── trpl15-01.svg │ │ ├── trpl15-02.svg │ │ ├── trpl15-03.svg │ │ ├── trpl15-04.svg │ │ └── trpl20-01.png ├── style-guide.md └── tools │ ├── docx-to-md.xsl │ └── src │ └── bin │ ├── concat_chapters.rs │ ├── convert_quotes.rs │ ├── lfp.rs │ ├── link2print.rs │ ├── remove_links.rs │ └── remove_markup.rs ├── CONTRIBUTING.md ├── COPYRIGHT ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── ci ├── build.sh ├── dictionary.txt ├── spellcheck.sh └── stable-check │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ └── main.rs ├── first-edition ├── book.toml └── src │ ├── README.md │ ├── SUMMARY.md │ ├── associated-types.md │ ├── attributes.md │ ├── bibliography.md │ ├── borrow-and-asref.md │ ├── casting-between-types.md │ ├── chapter_1.md │ ├── choosing-your-guarantees.md │ ├── closures.md │ ├── comments.md │ ├── concurrency.md │ ├── conditional-compilation.md │ ├── const-and-static.md │ ├── crates-and-modules.md │ ├── deref-coercions.md │ ├── documentation.md │ ├── drop.md │ ├── effective-rust.md │ ├── enums.md │ ├── error-handling.md │ ├── ffi.md │ ├── functions.md │ ├── generics.md │ ├── getting-started.md │ ├── glossary.md │ ├── guessing-game.md │ ├── if-let.md │ ├── if.md │ ├── iterators.md │ ├── lifetimes.md │ ├── loops.md │ ├── macros.md │ ├── match.md │ ├── method-syntax.md │ ├── mutability.md │ ├── operators-and-overloading.md │ ├── ownership.md │ ├── patterns.md │ ├── primitive-types.md │ ├── procedural-macros.md │ ├── raw-pointers.md │ ├── references-and-borrowing.md │ ├── release-channels.md │ ├── strings.md │ ├── structs.md │ ├── syntax-and-semantics.md │ ├── syntax-index.md │ ├── testing.md │ ├── the-stack-and-the-heap.md │ ├── theme │ ├── first-edition.css │ └── header.hbs │ ├── trait-objects.md │ ├── traits.md │ ├── type-aliases.md │ ├── ufcs.md │ ├── unsafe.md │ ├── unsized-types.md │ ├── using-rust-without-the-standard-library.md │ ├── variable-bindings.md │ └── vectors.md ├── index.md ├── redirects ├── README.md ├── SUMMARY.md ├── associated-types.md ├── attributes.md ├── bibliography.md ├── borrow-and-asref.md ├── casting-between-types.md ├── choosing-your-guarantees.md ├── closures.md ├── comments.md ├── compiler-plugins.md ├── concurrency.md ├── conditional-compilation.md ├── const-and-static.md ├── crates-and-modules.md ├── deref-coercions.md ├── documentation.md ├── drop.md ├── effective-rust.md ├── enums.md ├── error-handling.md ├── ffi.md ├── functions.md ├── generics.md ├── getting-started.md ├── glossary.md ├── guessing-game.md ├── if-let.md ├── if.md ├── iterators.md ├── lifetimes.md ├── loops.md ├── macros.md ├── match.md ├── method-syntax.md ├── mutability.md ├── operators-and-overloading.md ├── ownership.md ├── patterns.md ├── primitive-types.md ├── procedural-macros.md ├── raw-pointers.md ├── references-and-borrowing.md ├── release-channels.md ├── strings.md ├── structs.md ├── syntax-and-semantics.md ├── syntax-index.md ├── testing.md ├── the-stack-and-the-heap.md ├── trait-objects.md ├── traits.md ├── type-aliases.md ├── ufcs.md ├── unsafe.md ├── unsized-types.md ├── using-rust-without-the-standard-library.md ├── variable-bindings.md └── vectors.md └── second-edition ├── en ├── Cargo.lock ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── book.toml ├── convert-quotes.sh ├── doc-to-md.sh ├── dot │ ├── trpl04-01.dot │ ├── trpl04-02.dot │ ├── trpl04-03.dot │ ├── trpl04-04.dot │ ├── trpl04-05.dot │ ├── trpl04-06.dot │ ├── trpl15-01.dot │ ├── trpl15-02.dot │ └── trpl15-03.dot ├── nostarch.sh ├── nostarch │ ├── appendix.md │ ├── chapter00.md │ ├── chapter01.md │ ├── chapter02.md │ ├── chapter03.md │ ├── chapter04.md │ ├── chapter05.md │ ├── chapter06.md │ ├── chapter07.md │ ├── chapter08.md │ ├── chapter09.md │ ├── chapter10.md │ ├── chapter11.md │ ├── chapter12.md │ ├── chapter13.md │ ├── chapter14.md │ ├── chapter15.md │ ├── chapter16.md │ ├── chapter17.md │ ├── chapter18.md │ ├── chapter19.md │ ├── chapter20.md │ ├── foreword.md │ ├── introduction.md │ └── odt │ │ ├── appendix.docx │ │ ├── chapter00.docx │ │ ├── chapter01.docx │ │ ├── chapter02.doc │ │ ├── chapter03.docx │ │ ├── chapter04.docx │ │ ├── chapter05.docx │ │ ├── chapter06.docx │ │ ├── chapter07.docx │ │ ├── chapter08.docx │ │ ├── chapter09.docx │ │ ├── chapter10.docx │ │ ├── chapter11.docx │ │ ├── chapter12.docx │ │ ├── chapter13.docx │ │ ├── chapter14.docx │ │ ├── chapter15.docx │ │ ├── chapter16.docx │ │ ├── chapter17.docx │ │ ├── chapter18.docx │ │ ├── chapter19.docx │ │ ├── chapter20.docx │ │ └── index.docx ├── src │ ├── SUMMARY.md │ ├── appendix-00.md │ ├── appendix-01-keywords.md │ ├── appendix-02-operators.md │ ├── appendix-03-derivable-traits.md │ ├── appendix-04-macros.md │ ├── appendix-05-translation.md │ ├── appendix-06-newest-features.md │ ├── appendix-07-nightly-rust.md │ ├── ch00-00-introduction.md │ ├── ch01-00-getting-started.md │ ├── ch01-01-installation.md │ ├── ch01-02-hello-world.md │ ├── ch01-03-hello-cargo.md │ ├── ch02-00-guessing-game-tutorial.md │ ├── ch03-00-common-programming-concepts.md │ ├── ch03-01-variables-and-mutability.md │ ├── ch03-02-data-types.md │ ├── ch03-03-how-functions-work.md │ ├── ch03-04-comments.md │ ├── ch03-05-control-flow.md │ ├── ch04-00-understanding-ownership.md │ ├── ch04-01-what-is-ownership.md │ ├── ch04-02-references-and-borrowing.md │ ├── ch04-03-slices.md │ ├── ch05-00-structs.md │ ├── ch05-01-defining-structs.md │ ├── ch05-02-example-structs.md │ ├── ch05-03-method-syntax.md │ ├── ch06-00-enums.md │ ├── ch06-01-defining-an-enum.md │ ├── ch06-02-match.md │ ├── ch06-03-if-let.md │ ├── ch07-00-modules.md │ ├── ch07-01-mod-and-the-filesystem.md │ ├── ch07-02-controlling-visibility-with-pub.md │ ├── ch07-03-importing-names-with-use.md │ ├── ch08-00-common-collections.md │ ├── ch08-01-vectors.md │ ├── ch08-02-strings.md │ ├── ch08-03-hash-maps.md │ ├── ch09-00-error-handling.md │ ├── ch09-01-unrecoverable-errors-with-panic.md │ ├── ch09-02-recoverable-errors-with-result.md │ ├── ch09-03-to-panic-or-not-to-panic.md │ ├── ch10-00-generics.md │ ├── ch10-01-syntax.md │ ├── ch10-02-traits.md │ ├── ch10-03-lifetime-syntax.md │ ├── ch11-00-testing.md │ ├── ch11-01-writing-tests.md │ ├── ch11-02-running-tests.md │ ├── ch11-03-test-organization.md │ ├── ch12-00-an-io-project.md │ ├── ch12-01-accepting-command-line-arguments.md │ ├── ch12-02-reading-a-file.md │ ├── ch12-03-improving-error-handling-and-modularity.md │ ├── ch12-04-testing-the-librarys-functionality.md │ ├── ch12-05-working-with-environment-variables.md │ ├── ch12-06-writing-to-stderr-instead-of-stdout.md │ ├── ch13-00-functional-features.md │ ├── ch13-01-closures.md │ ├── ch13-02-iterators.md │ ├── ch13-03-improving-our-io-project.md │ ├── ch13-04-performance.md │ ├── ch14-00-more-about-cargo.md │ ├── ch14-01-release-profiles.md │ ├── ch14-02-publishing-to-crates-io.md │ ├── ch14-03-cargo-workspaces.md │ ├── ch14-04-installing-binaries.md │ ├── ch14-05-extending-cargo.md │ ├── ch15-00-smart-pointers.md │ ├── ch15-01-box.md │ ├── ch15-02-deref.md │ ├── ch15-03-drop.md │ ├── ch15-04-rc.md │ ├── ch15-05-interior-mutability.md │ ├── ch15-06-reference-cycles.md │ ├── ch16-00-concurrency.md │ ├── ch16-01-threads.md │ ├── ch16-02-message-passing.md │ ├── ch16-03-shared-state.md │ ├── ch16-04-extensible-concurrency-sync-and-send.md │ ├── ch17-00-oop.md │ ├── ch17-01-what-is-oo.md │ ├── ch17-02-trait-objects.md │ ├── ch17-03-oo-design-patterns.md │ ├── ch18-00-patterns.md │ ├── ch18-01-all-the-places-for-patterns.md │ ├── ch18-02-refutability.md │ ├── ch18-03-pattern-syntax.md │ ├── ch19-00-advanced-features.md │ ├── ch19-01-unsafe-rust.md │ ├── ch19-02-advanced-lifetimes.md │ ├── ch19-03-advanced-traits.md │ ├── ch19-04-advanced-types.md │ ├── ch19-05-advanced-functions-and-closures.md │ ├── ch20-00-final-project-a-web-server.md │ ├── ch20-01-single-threaded.md │ ├── ch20-02-multithreaded.md │ ├── ch20-03-graceful-shutdown-and-cleanup.md │ ├── foreword.md │ └── img │ │ ├── trpl04-01.svg │ │ ├── trpl04-02.svg │ │ ├── trpl04-03.svg │ │ ├── trpl04-04.svg │ │ ├── trpl04-05.svg │ │ ├── trpl04-06.svg │ │ ├── trpl14-01.png │ │ ├── trpl14-02.png │ │ ├── trpl14-03.png │ │ ├── trpl14-04.png │ │ ├── trpl15-01.svg │ │ ├── trpl15-02.svg │ │ ├── trpl15-03.svg │ │ ├── trpl15-04.svg │ │ └── trpl20-01.png ├── style-guide.md └── tools │ ├── docx-to-md.xsl │ └── src │ └── bin │ ├── concat_chapters.rs │ ├── convert_quotes.rs │ ├── lfp.rs │ ├── link2print.rs │ ├── remove_links.rs │ └── remove_markup.rs └── es ├── Cargo.lock ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── book.toml ├── convert-quotes.sh ├── doc-to-md.sh ├── dot ├── trpl04-01.dot ├── trpl04-02.dot ├── trpl04-03.dot ├── trpl04-04.dot ├── trpl04-05.dot ├── trpl04-06.dot ├── trpl15-01.dot ├── trpl15-02.dot └── trpl15-03.dot ├── nostarch.sh ├── nostarch ├── appendix.md ├── chapter00.md ├── chapter01.md ├── chapter02.md ├── chapter03.md ├── chapter04.md ├── chapter05.md ├── chapter06.md ├── chapter07.md ├── chapter08.md ├── chapter09.md ├── chapter10.md ├── chapter11.md ├── chapter12.md ├── chapter13.md ├── chapter14.md ├── chapter15.md ├── chapter16.md ├── chapter17.md ├── chapter18.md ├── chapter19.md ├── chapter20.md ├── foreword.md ├── introduction.md └── odt │ ├── appendix.docx │ ├── chapter00.docx │ ├── chapter01.docx │ ├── chapter02.doc │ ├── chapter03.docx │ ├── chapter04.docx │ ├── chapter05.docx │ ├── chapter06.docx │ ├── chapter07.docx │ ├── chapter08.docx │ ├── chapter09.docx │ ├── chapter10.docx │ ├── chapter11.docx │ ├── chapter12.docx │ ├── chapter13.docx │ ├── chapter14.docx │ ├── chapter15.docx │ ├── chapter16.docx │ ├── chapter17.docx │ ├── chapter18.docx │ ├── chapter19.docx │ ├── chapter20.docx │ └── index.docx ├── src ├── SUMMARY.md ├── appendix-00.md ├── appendix-01-keywords.md ├── appendix-02-operators.md ├── appendix-03-derivable-traits.md ├── appendix-04-macros.md ├── appendix-05-translation.md ├── appendix-06-newest-features.md ├── appendix-07-nightly-rust.md ├── ch00-00-introduction.md ├── ch01-00-getting-started.md ├── ch01-01-installation.md ├── ch01-02-hello-world.md ├── ch01-03-hello-cargo.md ├── ch02-00-guessing-game-tutorial.md ├── ch03-00-common-programming-concepts.md ├── ch03-01-variables-and-mutability.md ├── ch03-02-data-types.md ├── ch03-03-how-functions-work.md ├── ch03-04-comments.md ├── ch03-05-control-flow.md ├── ch04-00-understanding-ownership.md ├── ch04-01-what-is-ownership.md ├── ch04-02-references-and-borrowing.md ├── ch04-03-slices.md ├── ch05-00-structs.md ├── ch05-01-defining-structs.md ├── ch05-02-example-structs.md ├── ch05-03-method-syntax.md ├── ch06-00-enums.md ├── ch06-01-defining-an-enum.md ├── ch06-02-match.md ├── ch06-03-if-let.md ├── ch07-00-modules.md ├── ch07-01-mod-and-the-filesystem.md ├── ch07-02-controlling-visibility-with-pub.md ├── ch07-03-importing-names-with-use.md ├── ch08-00-common-collections.md ├── ch08-01-vectors.md ├── ch08-02-strings.md ├── ch08-03-hash-maps.md ├── ch09-00-error-handling.md ├── ch09-01-unrecoverable-errors-with-panic.md ├── ch09-02-recoverable-errors-with-result.md ├── ch09-03-to-panic-or-not-to-panic.md ├── ch10-00-generics.md ├── ch10-01-syntax.md ├── ch10-02-traits.md ├── ch10-03-lifetime-syntax.md ├── ch11-00-testing.md ├── ch11-01-writing-tests.md ├── ch11-02-running-tests.md ├── ch11-03-test-organization.md ├── ch12-00-an-io-project.md ├── ch12-01-accepting-command-line-arguments.md ├── ch12-02-reading-a-file.md ├── ch12-03-improving-error-handling-and-modularity.md ├── ch12-04-testing-the-librarys-functionality.md ├── ch12-05-working-with-environment-variables.md ├── ch12-06-writing-to-stderr-instead-of-stdout.md ├── ch13-00-functional-features.md ├── ch13-01-closures.md ├── ch13-02-iterators.md ├── ch13-03-improving-our-io-project.md ├── ch13-04-performance.md ├── ch14-00-more-about-cargo.md ├── ch14-01-release-profiles.md ├── ch14-02-publishing-to-crates-io.md ├── ch14-03-cargo-workspaces.md ├── ch14-04-installing-binaries.md ├── ch14-05-extending-cargo.md ├── ch15-00-smart-pointers.md ├── ch15-01-box.md ├── ch15-02-deref.md ├── ch15-03-drop.md ├── ch15-04-rc.md ├── ch15-05-interior-mutability.md ├── ch15-06-reference-cycles.md ├── ch16-00-concurrency.md ├── ch16-01-threads.md ├── ch16-02-message-passing.md ├── ch16-03-shared-state.md ├── ch16-04-extensible-concurrency-sync-and-send.md ├── ch17-00-oop.md ├── ch17-01-what-is-oo.md ├── ch17-02-trait-objects.md ├── ch17-03-oo-design-patterns.md ├── ch18-00-patterns.md ├── ch18-01-all-the-places-for-patterns.md ├── ch18-02-refutability.md ├── ch18-03-pattern-syntax.md ├── ch19-00-advanced-features.md ├── ch19-01-unsafe-rust.md ├── ch19-02-advanced-lifetimes.md ├── ch19-03-advanced-traits.md ├── ch19-04-advanced-types.md ├── ch19-05-advanced-functions-and-closures.md ├── ch20-00-final-project-a-web-server.md ├── ch20-01-single-threaded.md ├── ch20-02-multithreaded.md ├── ch20-03-graceful-shutdown-and-cleanup.md ├── foreword.md └── img │ ├── trpl04-01.svg │ ├── trpl04-02.svg │ ├── trpl04-03.svg │ ├── trpl04-04.svg │ ├── trpl04-05.svg │ ├── trpl04-06.svg │ ├── trpl14-01.png │ ├── trpl14-02.png │ ├── trpl14-03.png │ ├── trpl14-04.png │ ├── trpl15-01.svg │ ├── trpl15-02.svg │ ├── trpl15-03.svg │ ├── trpl15-04.svg │ └── trpl20-01.png ├── style-guide.md └── tools ├── docx-to-md.xsl └── src └── bin ├── concat_chapters.rs ├── convert_quotes.rs ├── lfp.rs ├── link2print.rs ├── remove_links.rs └── remove_markup.rs /2018-edition/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rust-book" 3 | version = "0.0.1" 4 | authors = ["Steve Klabnik "] 5 | description = "The Rust Book" 6 | 7 | [[bin]] 8 | name = "concat_chapters" 9 | path = "tools/src/bin/concat_chapters.rs" 10 | 11 | [[bin]] 12 | name = "lfp" 13 | path = "tools/src/bin/lfp.rs" 14 | 15 | [[bin]] 16 | name = "link2print" 17 | path = "tools/src/bin/link2print.rs" 18 | 19 | [[bin]] 20 | name = "remove_links" 21 | path = "tools/src/bin/remove_links.rs" 22 | 23 | [[bin]] 24 | name = "remove_markup" 25 | path = "tools/src/bin/remove_markup.rs" 26 | 27 | [[bin]] 28 | name = "convert_quotes" 29 | path = "tools/src/bin/convert_quotes.rs" 30 | 31 | [dependencies] 32 | walkdir = "0.1.5" 33 | docopt = "0.6.82" 34 | rustc-serialize = "0.3.19" 35 | regex = "0.1.73" 36 | lazy_static = "0.2.1" 37 | -------------------------------------------------------------------------------- /2018-edition/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010-2017 The Rust Project Developers 2 | 3 | Permission is hereby granted, free of charge, to any 4 | person obtaining a copy of this software and associated 5 | documentation files (the "Software"), to deal in the 6 | Software without restriction, including without 7 | limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software 10 | is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice 14 | shall be included in all copies or substantial portions 15 | of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 18 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 19 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 24 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. 26 | -------------------------------------------------------------------------------- /2018-edition/book.toml: -------------------------------------------------------------------------------- 1 | [book] 2 | title = "The Rust Programming Language" 3 | author = "Steve Klabnik and Carol Nichols, with Contributions from the Rust Community" 4 | -------------------------------------------------------------------------------- /2018-edition/convert-quotes.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2017 The Rust Project Developers. See the COPYRIGHT 3 | # file at the top-level directory of this distribution and at 4 | # http://rust-lang.org/COPYRIGHT. 5 | # 6 | # Licensed under the Apache License, Version 2.0 or the MIT license 8 | # , at your 9 | # option. This file may not be copied, modified, or distributed 10 | # except according to those terms. 11 | 12 | set -eu 13 | 14 | dir=$1 15 | 16 | mkdir -p "tmp/$dir" 17 | 18 | for f in $dir/*.md 19 | do 20 | cat "$f" | cargo run --bin convert_quotes > "tmp/$f" 21 | mv "tmp/$f" "$f" 22 | done 23 | -------------------------------------------------------------------------------- /2018-edition/dot/trpl04-01.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | rankdir=LR; 3 | overlap=false; 4 | dpi=300.0; 5 | node [shape="plaintext"]; 6 | 7 | table0[label=< 8 | 9 | 10 | 11 | 12 | 13 |
s1
namevalue
ptr
len5
capacity5
>]; 14 | table1[label=< 15 | 16 | 17 | 18 | 19 | 20 | 21 |
indexvalue
0h
1e
2l
3l
4o
>]; 22 | 23 | edge[tailclip="false"]; 24 | table0:pointer:c -> table1:pointee; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /2018-edition/dot/trpl04-02.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | rankdir=LR; 3 | overlap=false; 4 | dpi=300.0; 5 | node [shape="plaintext"]; 6 | 7 | table0[label=< 8 | 9 | 10 | 11 | 12 | 13 |
s1
namevalue
ptr
len5
capacity5
>]; 14 | table3[label=< 15 | 16 | 17 | 18 | 19 | 20 |
s2
namevalue
ptr
len5
capacity5
>]; 21 | 22 | table1[label=< 23 | 24 | 25 | 26 | 27 | 28 | 29 |
indexvalue
0h
1e
2l
3l
4o
>]; 30 | 31 | edge[tailclip="false"]; 32 | table0:pointer:c -> table1:pointee; 33 | table3:pointer:c -> table1:pointee; 34 | } 35 | 36 | -------------------------------------------------------------------------------- /2018-edition/dot/trpl04-03.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | rankdir=LR; 3 | overlap=false; 4 | dpi=300.0; 5 | node [shape="plaintext"]; 6 | 7 | table0[label=< 8 | 9 | 10 | 11 | 12 | 13 |
s2
namevalue
ptr
len5
capacity5
>]; 14 | table1[label=< 15 | 16 | 17 | 18 | 19 | 20 | 21 |
indexvalue
0h
1e
2l
3l
4o
>]; 22 | 23 | table3[label=< 24 | 25 | 26 | 27 | 28 | 29 |
s1
namevalue
ptr
len5
capacity5
>]; 30 | table4[label=< 31 | 32 | 33 | 34 | 35 | 36 | 37 |
indexvalue
0h
1e
2l
3l
4o
>]; 38 | 39 | 40 | edge[tailclip="false"]; 41 | table0:pointer:c -> table1:pointee; 42 | table3:pointer:c -> table4:pointee; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /2018-edition/dot/trpl04-04.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | rankdir=LR; 3 | overlap=false; 4 | dpi=300.0; 5 | node [shape="plaintext"]; 6 | 7 | table0[label=< 8 | 9 | 10 | 11 | 12 | 13 |
s1
namevalue
ptr
len5
capacity5
>]; 14 | table3[label=< 15 | 16 | 17 | 18 | 19 | 20 |
s2
namevalue
ptr
len5
capacity5
>]; 21 | 22 | table1[label=< 23 | 24 | 25 | 26 | 27 | 28 | 29 |
indexvalue
0h
1e
2l
3l
4o
>]; 30 | 31 | edge[tailclip="false"]; 32 | table0:pointer:c -> table1:pointee; 33 | table3:pointer:c -> table1:pointee; 34 | } 35 | 36 | -------------------------------------------------------------------------------- /2018-edition/dot/trpl04-05.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | rankdir=LR; 3 | overlap=false; 4 | dpi=300.0; 5 | node [shape="plaintext"]; 6 | 7 | table0[label=< 8 | 9 | 10 | 11 |
s
namevalue
ptr
>]; 12 | table1[label=< 13 | 14 | 15 | 16 | 17 | 18 |
s1
namevalue
ptr
len5
capacity5
>]; 19 | table2[label=< 20 | 21 | 22 | 23 | 24 | 25 | 26 |
indexvalue
0h
1e
2l
3l
4o
>]; 27 | 28 | edge[tailclip="false"]; 29 | table1:pointer:c -> table2:pointee; 30 | table0:borrower:c -> table1:borrowee; 31 | } 32 | 33 | -------------------------------------------------------------------------------- /2018-edition/dot/trpl04-06.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | rankdir=LR; 3 | overlap=false; 4 | dpi=300.0; 5 | node [shape="plaintext"]; 6 | 7 | table0[label=< 8 | 9 | 10 | 11 | 12 |
world
namevalue
ptr
len5
>]; 13 | 14 | table3[label=< 15 | 16 | 17 | 18 | 19 | 20 |
s
namevalue
ptr
len11
capacity11
>]; 21 | table4[label=< 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 |
indexvalue
0h
1e
2l
3l
4o
5
6w
7o
8r
9l
10d
>]; 35 | 36 | 37 | edge[tailclip="false"]; 38 | table0:pointer2:c -> table4:pointee2; 39 | table3:pointer:c -> table4:pointee; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /2018-edition/dot/trpl15-01.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | rankdir=LR; 3 | overlap=false; 4 | dpi=300.0; 5 | node [shape="plaintext"]; 6 | 7 | table0[label=< 8 | 9 | 22 |
Cons
i32 10 | 11 | 21 |
Cons
i32 12 | 13 | 20 |
Cons
i32 14 | 15 | 19 |
Cons
i32 16 | 17 | 18 |
Cons
i32
>]; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /2018-edition/dot/trpl15-02.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | rankdir=LR; 3 | overlap=false; 4 | dpi=300.0; 5 | node [shape="plaintext"]; 6 | 7 | table0[label=< 8 | 9 | 10 | 16 |
Cons
i32 11 | 12 | 13 | 14 |
Box
usize
15 |
>]; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /2018-edition/dot/trpl15-03.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | rankdir=LR; 3 | overlap=false; 4 | dpi=300.0; 5 | node [shape="plaintext"]; 6 | 7 | table4[label=< 8 | 9 |
b
>]; 10 | 11 | table5[label=< 12 | 13 |
3
>]; 14 | 15 | 16 | table0[label=< 17 | 18 |
a
>]; 19 | 20 | table1[label=< 21 | 22 |
5
>]; 23 | 24 | table2[label=< 25 | 26 |
10
>]; 27 | 28 | table3[label=< 29 | 30 |
Nil
>]; 31 | 32 | 33 | table6[label=< 34 | 35 |
c
>]; 36 | 37 | table7[label=< 38 | 39 |
4
>]; 40 | 41 | 42 | edge[tailclip="false"]; 43 | table0:ptr0:c -> table1:pte0; 44 | table1:ptr1:c -> table2:pte1; 45 | table2:ptr2:c -> table3:pte2; 46 | table4:ptr4:c -> table5:pte4; 47 | table5:ptr5:c -> table1:pte0; 48 | table6:ptr6:c -> table7:pte6; 49 | table7:ptr7:c -> table1:pte0; 50 | } 51 | 52 | -------------------------------------------------------------------------------- /2018-edition/src/appendix-00.md: -------------------------------------------------------------------------------- 1 | # Appendix 2 | 3 | The following sections contain reference material you may find useful in your 4 | Rust journey. 5 | -------------------------------------------------------------------------------- /2018-edition/src/appendix-05-translation.md: -------------------------------------------------------------------------------- 1 | ## Appendix E: Translations of the Book 2 | 3 | For resources in languages other than English. Most are still in progress; see 4 | [the Translations label][label] to help or let us know about a new translation! 5 | 6 | [label]: https://github.com/rust-lang/book/issues?q=is%3Aopen+is%3Aissue+label%3ATranslations 7 | 8 | - [Português](https://github.com/rust-br/rust-book-pt-br) (BR) 9 | - [Português](https://github.com/nunojesus/rust-book-pt-pt) (PT) 10 | - [Tiếng việt](https://github.com/hngnaig/rust-lang-book/tree/vi-VN) 11 | - [简体中文](http://www.broadview.com.cn/article/144), [alternate](https://github.com/KaiserY/trpl-zh-cn) 12 | - [Українська](https://github.com/pavloslav/rust-book-uk-ua) 13 | - [Español](https://github.com/thecodix/book) 14 | - [Italiano](https://github.com/CodelessFuture/trpl2-it) 15 | - [Русский](https://github.com/iDeBugger/rust-book-ru) 16 | - [한국어](https://github.com/rinthel/rust-lang-book-ko) 17 | - [日本語](https://github.com/hazama-yuinyan/book) 18 | - [Français](https://github.com/quadrifoglio/rust-book-fr) 19 | - [Polski](https://github.com/paytchoo/book-pl) 20 | - [עברית](https://github.com/idanmel/rust-book-heb) 21 | - [Cebuano](https://github.com/agentzero1/book) 22 | - [Tagalog](https://github.com/josephace135/book) 23 | -------------------------------------------------------------------------------- /2018-edition/src/ch01-00-getting-started.md: -------------------------------------------------------------------------------- 1 | # Getting Started 2 | 3 | 6 | 7 | 8 | Let’s get your Rust journey started! In this chapter, we’ll discuss: 9 | 10 | - Installing Rust on Linux, Mac, or Windows 11 | - Writing a program that prints “Hello, world!” 12 | - Using `cargo`, Rust’s package manager and build system 13 | -------------------------------------------------------------------------------- /2018-edition/src/ch03-00-common-programming-concepts.md: -------------------------------------------------------------------------------- 1 | # Common Programming Concepts 2 | 3 | This chapter covers concepts that appear in almost every programming language 4 | and how they work in Rust. Many programming languages have much in common at 5 | their core. None of the concepts presented in this chapter are unique to Rust, 6 | but we’ll discuss them in the context of Rust and explain the conventions 7 | around using these concepts. 8 | 9 | Specifically, you’ll learn about variables, basic types, functions, comments, 10 | and control flow. These foundations will be in every Rust program, and learning 11 | them early will give you a strong core to start from. 12 | 13 | > ### Keywords 14 | > 15 | > The Rust language has a set of *keywords* that are reserved for use by 16 | > the language only, much as in other languages. Keep in mind that you cannot 17 | > use these words as names of variables or functions. Most of the keywords have 18 | > special meanings, and you’ll be using them to do various tasks in your Rust 19 | > programs; a few have no current functionality associated with them but have 20 | > been reserved for functionality that might be added to Rust in the future. You 21 | > can find a list of the keywords in Appendix A. 22 | -------------------------------------------------------------------------------- /2018-edition/src/ch03-04-comments.md: -------------------------------------------------------------------------------- 1 | ## Comments 2 | 3 | All programmers strive to make their code easy to understand, but sometimes 4 | extra explanation is warranted. In these cases, programmers leave notes, or 5 | *comments*, in their source code that the compiler will ignore but people 6 | reading the source code may find useful. 7 | 8 | Here’s a simple comment: 9 | 10 | ```rust 11 | // Hello, world. 12 | ``` 13 | 14 | In Rust, comments must start with two slashes and continue until the end of the 15 | line. For comments that extend beyond a single line, you’ll need to include 16 | `//` on each line, like this: 17 | 18 | ```rust 19 | // So we’re doing something complicated here, long enough that we need 20 | // multiple lines of comments to do it! Whew! Hopefully, this comment will 21 | // explain what’s going on. 22 | ``` 23 | 24 | Comments can also be placed at the end of lines containing code: 25 | 26 | Filename: src/main.rs 27 | 28 | ```rust 29 | fn main() { 30 | let lucky_number = 7; // I’m feeling lucky today. 31 | } 32 | ``` 33 | 34 | But you’ll more often see them used in this format, with the comment on a 35 | separate line above the code it’s annotating: 36 | 37 | Filename: src/main.rs 38 | 39 | ```rust 40 | fn main() { 41 | // I’m feeling lucky today. 42 | let lucky_number = 7; 43 | } 44 | ``` 45 | 46 | Rust also has another kind of comment, documentation comments, which we’ll 47 | discuss in Chapter 14. 48 | -------------------------------------------------------------------------------- /2018-edition/src/ch04-00-understanding-ownership.md: -------------------------------------------------------------------------------- 1 | # Understanding Ownership 2 | 3 | Ownership is Rust’s most unique feature, and it enables Rust to make memory 4 | safety guarantees without needing a garbage collector. Therefore, it’s 5 | important to understand how ownership works in Rust. In this chapter, we’ll 6 | talk about ownership as well as several related features: borrowing, slices, 7 | and how Rust lays data out in memory. 8 | -------------------------------------------------------------------------------- /2018-edition/src/ch05-00-structs.md: -------------------------------------------------------------------------------- 1 | # Using Structs to Structure Related Data 2 | 3 | A *struct*, or *structure*, is a custom data type that lets you name and 4 | package together multiple related values that make up a meaningful group. If 5 | you’re familiar with an object-oriented language, a *struct* is like an 6 | object’s data attributes. In this chapter, we’ll compare and contrast tuples 7 | with structs, demonstrate how to use structs, and discuss how to define methods 8 | and associated functions to specify behavior associated with a struct’s data. 9 | Structs and enums (discussed in Chapter 6) are the building blocks for creating 10 | new types in your program’s domain to take full advantage of Rust’s compile 11 | time type checking. 12 | -------------------------------------------------------------------------------- /2018-edition/src/ch06-00-enums.md: -------------------------------------------------------------------------------- 1 | # Enums and Pattern Matching 2 | 3 | In this chapter we’ll look at *enumerations*, also referred to as *enums*. 4 | Enums allow you to define a type by enumerating its possible values. First, 5 | we’ll define and use an enum to show how an enum can encode meaning along with 6 | data. Next, we’ll explore a particularly useful enum, called `Option`, which 7 | expresses that a value can be either something or nothing. Then we’ll look at 8 | how pattern matching in the `match` expression makes it easy to run different 9 | code for different values of an enum. Finally, we’ll cover how the `if let` 10 | construct is another convenient and concise idiom available to you to handle 11 | enums in your code. 12 | 13 | Enums are a feature in many languages, but their capabilities differ in each 14 | language. Rust’s enums are most similar to *algebraic data types* in functional 15 | languages, such as F#, OCaml, and Haskell. 16 | -------------------------------------------------------------------------------- /2018-edition/src/ch07-00-modules.md: -------------------------------------------------------------------------------- 1 | # Using Modules to Reuse and Organize Code 2 | 3 | When you start writing programs in Rust, your code might live solely in the 4 | `main` function. As your code grows, you’ll eventually move functionality into 5 | other functions for reuse and better organization. By splitting your code into 6 | smaller chunks, you make each chunk easier to understand on its own. But what 7 | happens if you have too many functions? Rust has a module system that enables 8 | the reuse of code in an organized fashion. 9 | 10 | In the same way that you extract lines of code into a function, you can extract 11 | functions (and other code, like structs and enums) into different modules. A 12 | *module* is a namespace that contains definitions of functions or types, and 13 | you can choose whether those definitions are visible outside their module 14 | (public) or not (private). Here’s an overview of how modules work: 15 | 16 | * The `mod` keyword declares a new module. Code within the module appears 17 | either immediately following this declaration within curly brackets or in 18 | another file. 19 | * By default, functions, types, constants, and modules are private. The `pub` 20 | keyword makes an item public and therefore visible outside its namespace. 21 | * The `use` keyword brings modules, or the definitions inside modules, into 22 | scope so it’s easier to refer to them. 23 | 24 | We’ll look at each of these parts to see how they fit into the whole. 25 | -------------------------------------------------------------------------------- /2018-edition/src/ch08-00-common-collections.md: -------------------------------------------------------------------------------- 1 | # Common Collections 2 | 3 | Rust’s standard library includes a number of very useful data structures called 4 | *collections*. Most other data types represent one specific value, but 5 | collections can contain multiple values. Unlike the built-in array and tuple 6 | types, the data these collections point to is stored on the heap, which means 7 | the amount of data does not need to be known at compile time and can grow or 8 | shrink as the program runs. Each kind of collection has different capabilities 9 | and costs, and choosing an appropriate one for your current situation is a 10 | skill you’ll develop over time. In this chapter, we’ll discuss three 11 | collections that are used very often in Rust programs: 12 | 13 | * A *vector* allows you to store a variable number of values next to each other. 14 | * A *string* is a collection of characters. We’ve mentioned the `String` type 15 | previously, but in this chapter we’ll talk about it in depth. 16 | * A *hash map* allows you to associate a value with a particular key. It’s a 17 | particular implementation of the more general data structure called a *map*. 18 | 19 | To learn about the other kinds of collections provided by the standard library, 20 | see [the documentation][collections]. 21 | 22 | [collections]: ../../std/collections/index.html 23 | 24 | We’ll discuss how to create and update vectors, strings, and hash maps, as well 25 | as what makes each special. 26 | -------------------------------------------------------------------------------- /2018-edition/src/ch09-00-error-handling.md: -------------------------------------------------------------------------------- 1 | # Error Handling 2 | 3 | Rust’s commitment to reliability extends to error handling. Errors are a fact 4 | of life in software, so Rust has a number of features for handling situations 5 | in which something goes wrong. In many cases, Rust requires you to acknowledge 6 | the possibility of an error and take some action before your code will compile. 7 | This requirement makes your program more robust by ensuring that you’ll 8 | discover errors and handle them appropriately before you’ve deployed your code 9 | to production! 10 | 11 | Rust groups errors into two major categories: *recoverable* and *unrecoverable* 12 | errors. For a recoverable error, such as a file not found error, it’s 13 | reasonable to report the problem to the user and retry the operation. 14 | Unrecoverable errors are always symptoms of bugs, like trying to access a 15 | location beyond the end of an array. 16 | 17 | Most languages don’t distinguish between these two kinds of errors and handle 18 | both in the same way, using mechanisms such as exceptions. Rust doesn’t have 19 | exceptions. Instead, it has the type `Result` for recoverable errors and 20 | the `panic!` macro that stops execution when the program encounters an 21 | unrecoverable error. This chapter covers calling `panic!` first and then talks 22 | about returning `Result` values. Additionally, we’ll explore 23 | considerations when deciding whether to try to recover from an error or to stop 24 | execution. 25 | -------------------------------------------------------------------------------- /2018-edition/src/ch13-00-functional-features.md: -------------------------------------------------------------------------------- 1 | # Functional Language Features: Iterators and Closures 2 | 3 | Rust’s design has taken inspiration from many existing languages and 4 | techniques, and one significant influence is *functional programming*. 5 | Programming in a functional style often includes using functions as values by 6 | passing them in arguments, returning them from other functions, assigning them 7 | to variables for later execution, and so forth. 8 | 9 | In this chapter, we won’t debate the issue of what functional programming is or 10 | isn’t but will instead discuss some features of Rust that are similar to 11 | features in many languages often referred to as functional. 12 | 13 | More specifically, we’ll cover: 14 | 15 | * *Closures*, a function-like construct you can store in a variable 16 | * *Iterators*, a way of processing a series of elements 17 | * How to use these two features to improve the I/O project in Chapter 12 18 | * The performance of these two features (Spoiler alert: they’re faster than you 19 | might think!) 20 | 21 | Other Rust features, such as pattern matching and enums, which we’ve covered in 22 | other chapters, are influenced by the functional style as well. Mastering 23 | closures and iterators is an important part of writing idiomatic, fast Rust 24 | code, so we’ll devote this entire chapter to them. 25 | -------------------------------------------------------------------------------- /2018-edition/src/ch14-00-more-about-cargo.md: -------------------------------------------------------------------------------- 1 | # More About Cargo and Crates.io 2 | 3 | So far we’ve used only the most basic features of Cargo to build, run, and test 4 | our code, but it can do a lot more. In this chapter, we’ll discuss some of its 5 | other, more advanced features to show you how to do the following: 6 | 7 | * Customize your build through release profiles 8 | * Publish libraries on [crates.io](https://crates.io) 9 | * Organize large projects with workspaces 10 | * Install binaries from [crates.io](https://crates.io) 11 | * Extend Cargo using custom commands 12 | 13 | Cargo can do even more than what we cover in this chapter, so for a full 14 | explanation of all its features, see [its 15 | documentation](https://doc.rust-lang.org/cargo/). 16 | -------------------------------------------------------------------------------- /2018-edition/src/ch14-05-extending-cargo.md: -------------------------------------------------------------------------------- 1 | ## Extending Cargo with Custom Commands 2 | 3 | Cargo is designed so you can extend it with new subcommands without having to 4 | modify Cargo. If a binary in your `$PATH` is named `cargo-something`, you can 5 | run it as if it was a Cargo subcommand by running `cargo something`. Custom 6 | commands like this are also listed when you run `cargo --list`. Being able to 7 | use `cargo install` to install extensions and then run them just like the 8 | built-in Cargo tools is a super convenient benefit of Cargo’s design! 9 | 10 | ## Summary 11 | 12 | Sharing code with Cargo and [crates.io](https://crates.io) is 13 | part of what makes the Rust ecosystem useful for many different tasks. Rust’s 14 | standard library is small and stable, but crates are easy to share, use, and 15 | improve on a timeline different from that of the language. Don’t be shy about 16 | sharing code that’s useful to you on [crates.io](https://crates.io); it’s likely that it will be useful to someone else as well! 18 | -------------------------------------------------------------------------------- /2018-edition/src/ch17-00-oop.md: -------------------------------------------------------------------------------- 1 | # Object Oriented Programming Features of Rust 2 | 3 | Object-oriented programming (OOP) is a way of modeling programs. Objects came 4 | from Simula in the 1960s. Those objects influenced Alan Kay’s programming 5 | architecture in which objects pass messages to each other. He coined the term 6 | *object-oriented programming* in 1967 to describe this architecture. Many 7 | competing definitions describe what OOP is; some definitions would classify 8 | Rust as object oriented, but other definitions would not. In this chapter, 9 | we’ll explore certain characteristics that are commonly considered object 10 | oriented and how those characteristics translate to idiomatic Rust. We’ll then 11 | show you how to implement an object-oriented design pattern in Rust and discuss 12 | the trade-offs of doing so versus implementing a solution using some of Rust’s 13 | strengths instead. 14 | -------------------------------------------------------------------------------- /2018-edition/src/ch18-00-patterns.md: -------------------------------------------------------------------------------- 1 | # Patterns and Matching 2 | 3 | Patterns are a special syntax in Rust for matching against the structure of 4 | types, both complex and simple. Using patterns in conjunction with `match` 5 | expressions and other constructs gives you more control over a program’s 6 | control flow. A pattern consists of some combination of the following: 7 | 8 | * Literals 9 | * Destructured arrays, enums, structs, or tuples 10 | * Variables 11 | * Wildcards 12 | * Placeholders 13 | 14 | These components describe the shape of the data we’re working with, which we 15 | then match against values to determine whether our program has the correct data 16 | to continue running a particular piece of code. 17 | 18 | To use a pattern, we compare it to some value. If the pattern matches the 19 | value, we use the value parts in our code. Recall the `match` expressions in 20 | Chapter 6 that used patterns, such as the coin sorting machine example. If the 21 | value fits the shape of the pattern, we can use the named pieces. If it 22 | doesn’t, the code associated with the pattern won’t run. 23 | 24 | This chapter is a reference on all things related to patterns. We’ll cover the 25 | valid places to use patterns, the difference between *refutable* and 26 | *irrefutable* patterns, and the different kinds of pattern syntax that you 27 | might see. By the end of the chapter, you’ll know how to use patterns to 28 | express many concepts in a clear way. 29 | -------------------------------------------------------------------------------- /2018-edition/src/ch19-00-advanced-features.md: -------------------------------------------------------------------------------- 1 | # Advanced Features 2 | 3 | By now, you’ve learned the most commonly used parts of the Rust programming 4 | language. Before we do one more project in Chapter 20, we’ll look at a few 5 | aspects of the language you might run into every once in a while. You can use 6 | this chapter as a reference for when you encounter any unknowns when using 7 | Rust. The features you’ll learn to use in this chapter are useful in very 8 | specific situations. Although you might not reach for them often, we want to 9 | make sure you have a grasp of all the features Rust has to offer. 10 | 11 | In this chapter, we’ll cover: 12 | 13 | * Unsafe Rust: How to opt out of some of Rust’s guarantees and take 14 | responsibility for manually upholding those guarantees 15 | * Advanced lifetimes: Syntax for complex lifetime situations 16 | * Advanced traits: Associated types, default type parameters, fully qualified 17 | syntax, supertraits, and the newtype pattern in relation to traits 18 | * Advanced types: More about the newtype pattern, type aliases, the *never* 19 | type, and dynamically sized types 20 | * Advanced functions and closures: Function pointers and returning closures 21 | 22 | It’s a panoply of Rust features with something for everyone! Let’s dive in! 23 | -------------------------------------------------------------------------------- /2018-edition/src/ch20-00-final-project-a-web-server.md: -------------------------------------------------------------------------------- 1 | # Final Project: Building a Multithreaded Web Server 2 | 3 | It’s been a long journey, but here we are! The end of the book. Parting is such 4 | sweet sorrow. But before we go, let’s build one more project together, to show 5 | off some of the concepts we covered in these final chapters, as well as recap 6 | some lessons from earlier. 7 | 8 | For our final project we’re going to make a web server that only says “hello”; 9 | which will look like Figure 20-1 in a web browser: 10 | 11 | ![hello from rust](img/trpl20-01.png) 12 | 13 | Figure 20-1: Our final shared project together 14 | 15 | Here’s the plan of how we’ll build the web server: 16 | 17 | 1. Learn a little bit about TCP and HTTP 18 | 2. Listen for TCP connections on a socket 19 | 3. Parse a small number of HTTP requests 20 | 4. Create a proper HTTP response 21 | 5. Improve the throughput of our server with a thread pool 22 | 23 | Before we get started, however, there’s one thing we should mention: the method 24 | we use here will not be the best way to build a web server with Rust. There are 25 | a number of production-ready crates available on *https://crates.io* that 26 | provide much more complete web server and thread pool implementations than we 27 | are going to build. 28 | 29 | However, for this chapter, our intention is to help you learn, not to take the 30 | easy route. Because Rust is a systems programming language, we’re able to 31 | choose what level of abstraction we want to work with, and can go to a lower 32 | level than is possible or practical in other languages. We’ll therefore write 33 | the basic HTTP server and thread pool ourselves so you can learn the general 34 | ideas and techniques behind the crates you might use in the future. 35 | -------------------------------------------------------------------------------- /2018-edition/src/img/trpl14-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/2018-edition/src/img/trpl14-01.png -------------------------------------------------------------------------------- /2018-edition/src/img/trpl14-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/2018-edition/src/img/trpl14-02.png -------------------------------------------------------------------------------- /2018-edition/src/img/trpl14-03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/2018-edition/src/img/trpl14-03.png -------------------------------------------------------------------------------- /2018-edition/src/img/trpl14-04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/2018-edition/src/img/trpl14-04.png -------------------------------------------------------------------------------- /2018-edition/src/img/trpl15-02.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | %3 11 | 12 | 13 | 14 | table0 15 | 16 | Cons 17 | 18 | i32 19 | 20 | 21 | Box 22 | 23 | usize 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /2018-edition/src/img/trpl20-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/2018-edition/src/img/trpl20-01.png -------------------------------------------------------------------------------- /2018-edition/style-guide.md: -------------------------------------------------------------------------------- 1 | # Style Guide 2 | 3 | ## Prose 4 | 5 | * Prefer title case for chapter/section headings, ex: `## Generating a Secret 6 | Number` rather than `## Generating a secret number`. 7 | * Prefer italics over single quotes when calling out a term, ex: `is an 8 | *associated function* of` rather than `is an ‘associated function’ of`. 9 | * When talking about a method in prose, DO NOT include the parentheses, ex: 10 | `read_line` rather than `read_line()`. 11 | * Hard wrap at 80 chars 12 | * Prefer not mixing code and not-code in one word, ex: ``Remember when we wrote 13 | `use std::io`?`` rather than ``Remember when we `use`d `std::io`?`` 14 | 15 | ## Code 16 | 17 | * Add the file name before markdown blocks to make it clear which file we're 18 | talking about, when applicable. 19 | * When making changes to code, make it clear which parts of the code changed 20 | and which stayed the same... not sure how to do this yet 21 | * Split up long lines as appropriate to keep them under 80 chars if possible 22 | * Use `bash` syntax highlighting for command line output code blocks 23 | 24 | ## Links 25 | 26 | Once all the scripts are done: 27 | 28 | * If a link shouldn't be printed, mark it to be ignored 29 | * This includes all "Chapter XX" intra-book links, which *should* be links 30 | for the HTML version 31 | * Make intra-book links and stdlib API doc links relative so they work whether 32 | the book is read offline or on docs.rust-lang.org 33 | * Use markdown links and keep in mind that they will be changed into `text at 34 | *url*` in print, so word them in a way that it reads well in that format 35 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 The Rust Project Developers 2 | 3 | Permission is hereby granted, free of charge, to any 4 | person obtaining a copy of this software and associated 5 | documentation files (the "Software"), to deal in the 6 | Software without restriction, including without 7 | limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software 10 | is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice 14 | shall be included in all copies or substantial portions 15 | of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 18 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 19 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 24 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. 26 | -------------------------------------------------------------------------------- /ci/build.sh: -------------------------------------------------------------------------------- 1 | # Copyright 2016 The Rust Project Developers. See the COPYRIGHT 2 | # file at the top-level directory of this distribution and at 3 | # http://rust-lang.org/COPYRIGHT. 4 | # 5 | # Licensed under the Apache License, Version 2.0 or the MIT license 7 | # , at your 8 | # option. This file may not be copied, modified, or distributed 9 | # except according to those terms. 10 | 11 | set -e 12 | 13 | export PATH=$PATH:/home/travis/.cargo/bin; 14 | 15 | # feature check 16 | cd ci/stable-check 17 | 18 | cargo run -- ../../first-edition/src 19 | cargo run -- ../../second-edition/src 20 | cargo run -- ../../2018-edition/src 21 | 22 | cd ../.. 23 | 24 | # tests for the first edition 25 | cd first-edition 26 | echo 'Testing first edition...' 27 | mdbook test 28 | echo 'Building first edition...' 29 | mdbook build 30 | 31 | cd .. 32 | 33 | # tests for the second edition 34 | cd second-edition 35 | echo 'Spellchecking second edition...' 36 | bash ../ci/spellcheck.sh list 37 | echo 'Testing second edition...' 38 | mdbook test 39 | echo 'Building second edition...' 40 | mdbook build 41 | echo 'Linting second edition for local file paths...' 42 | cargo run --bin lfp src 43 | 44 | cd .. 45 | 46 | # tests for the 2018 edition 47 | cd 2018-edition 48 | echo 'Spellchecking 2018 edition...' 49 | bash ../ci/spellcheck.sh list 50 | echo 'Testing 2018 edition...' 51 | mdbook test 52 | echo 'Building 2018 edition...' 53 | mdbook build 54 | echo 'Linting 2018 edition for local file paths...' 55 | cargo run --bin lfp src 56 | -------------------------------------------------------------------------------- /ci/stable-check/Cargo.lock: -------------------------------------------------------------------------------- 1 | [root] 2 | name = "stable-check" 3 | version = "0.1.0" 4 | 5 | -------------------------------------------------------------------------------- /ci/stable-check/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "stable-check" 3 | version = "0.1.0" 4 | authors = ["steveklabnik "] 5 | 6 | [dependencies] 7 | -------------------------------------------------------------------------------- /ci/stable-check/src/main.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use std::error::Error; 12 | use std::env; 13 | use std::fs; 14 | use std::fs::File; 15 | use std::io::prelude::*; 16 | use std::path::Path; 17 | 18 | fn main() { 19 | let arg = env::args().nth(1).unwrap_or_else(|| { 20 | println!("Please pass a src directory as the first argument"); 21 | std::process::exit(1); 22 | }); 23 | 24 | match check_directory(&Path::new(&arg)) { 25 | Ok(()) => println!("passed!"), 26 | Err(e) => { 27 | println!("Error: {}", e); 28 | std::process::exit(1); 29 | } 30 | } 31 | 32 | } 33 | 34 | fn check_directory(dir: &Path) -> Result<(), Box> { 35 | for entry in fs::read_dir(dir)? { 36 | let entry = entry?; 37 | let path = entry.path(); 38 | 39 | if path.is_dir() { 40 | continue; 41 | } 42 | 43 | let mut file = File::open(&path)?; 44 | let mut contents = String::new(); 45 | file.read_to_string(&mut contents)?; 46 | 47 | if contents.contains("#![feature") { 48 | return Err(From::from(format!("Feature flag found in {:?}", path))); 49 | } 50 | } 51 | 52 | Ok(()) 53 | } 54 | -------------------------------------------------------------------------------- /first-edition/book.toml: -------------------------------------------------------------------------------- 1 | [book] 2 | title = "The Rust Programming Language" 3 | author = "The Rust Project Developers" 4 | 5 | [output.html] 6 | additional-css = ["src/theme/first-edition.css"] 7 | -------------------------------------------------------------------------------- /first-edition/src/README.md: -------------------------------------------------------------------------------- 1 | # The Rust Programming Language 2 | 3 | Welcome! This book will teach you about the [Rust Programming Language][rust]. 4 | Rust is a systems programming language focused on three goals: safety, speed, 5 | and concurrency. It maintains these goals without having a garbage collector, 6 | making it a useful language for a number of use cases other languages aren’t 7 | good at: embedding in other languages, programs with specific space and time 8 | requirements, and writing low-level code, like device drivers and operating 9 | systems. It improves on current languages targeting this space by having a 10 | number of compile-time safety checks that produce no runtime overhead, while 11 | eliminating all data races. Rust also aims to achieve ‘zero-cost abstractions’ 12 | even though some of these abstractions feel like those of a high-level language. 13 | Even then, Rust still allows precise control like a low-level language would. 14 | 15 | [rust]: https://www.rust-lang.org 16 | 17 | “The Rust Programming Language” is split into chapters. This introduction 18 | is the first. After this: 19 | 20 | * [Getting started][gs] - Set up your computer for Rust development. 21 | * [Tutorial: Guessing Game][gg] - Learn some Rust with a small project. 22 | * [Syntax and Semantics][ss] - Each bit of Rust, broken down into small chunks. 23 | * [Effective Rust][er] - Higher-level concepts for writing excellent Rust code. 24 | * [Glossary][gl] - A reference of terms used in the book. 25 | * [Bibliography][bi] - Background on Rust's influences, papers about Rust. 26 | 27 | [gs]: getting-started.html 28 | [gg]: guessing-game.html 29 | [er]: effective-rust.html 30 | [ss]: syntax-and-semantics.html 31 | [gl]: glossary.html 32 | [bi]: bibliography.html 33 | 34 | ## Source Code 35 | 36 | The source files from which this book is generated can be found on 37 | [GitHub][book]. 38 | 39 | [book]: https://github.com/rust-lang/book/tree/master/first-edition/src -------------------------------------------------------------------------------- /first-edition/src/attributes.md: -------------------------------------------------------------------------------- 1 | # Attributes 2 | 3 | Declarations can be annotated with ‘attributes’ in Rust. They look like this: 4 | 5 | ```rust 6 | #[test] 7 | # fn foo() {} 8 | ``` 9 | 10 | or like this: 11 | 12 | ```rust 13 | # mod foo { 14 | #![test] 15 | # } 16 | ``` 17 | 18 | The difference between the two is the `!`, which changes what the attribute 19 | applies to: 20 | 21 | ```rust,ignore 22 | #[foo] 23 | struct Foo; 24 | 25 | mod bar { 26 | #![bar] 27 | } 28 | ``` 29 | 30 | The `#[foo]` attribute applies to the next item, which is the `struct` 31 | declaration. The `#![bar]` attribute applies to the item enclosing it, which is 32 | the `mod` declaration. Otherwise, they’re the same. Both change the meaning of 33 | the item they’re attached to somehow. 34 | 35 | For example, consider a function like this: 36 | 37 | ```rust 38 | #[test] 39 | fn check() { 40 | assert_eq!(2, 1 + 1); 41 | } 42 | ``` 43 | 44 | It is marked with `#[test]`. This means it’s special: when you run 45 | [tests][tests], this function will execute. When you compile as usual, it won’t 46 | even be included. This function is now a test function. 47 | 48 | [tests]: testing.html 49 | 50 | Attributes may also have additional data: 51 | 52 | ```rust 53 | #[inline(always)] 54 | fn super_fast_fn() { 55 | # } 56 | ``` 57 | 58 | Or even keys and values: 59 | 60 | ```rust 61 | #[cfg(target_os = "macos")] 62 | mod macos_only { 63 | # } 64 | ``` 65 | 66 | Rust attributes are used for a number of different things. There is a full list 67 | of attributes [in the reference][reference]. Currently, you are not allowed to 68 | create your own attributes, the Rust compiler defines them. 69 | 70 | [reference]: ../../reference/attributes.html 71 | -------------------------------------------------------------------------------- /first-edition/src/chapter_1.md: -------------------------------------------------------------------------------- 1 | # Chapter 1 2 | -------------------------------------------------------------------------------- /first-edition/src/drop.md: -------------------------------------------------------------------------------- 1 | # Drop 2 | 3 | Now that we’ve discussed traits, let’s talk about a particular trait provided 4 | by the Rust standard library, [`Drop`][drop]. The `Drop` trait provides a way 5 | to run some code when a value goes out of scope. For example: 6 | 7 | [drop]: ../../std/ops/trait.Drop.html 8 | 9 | ```rust 10 | struct HasDrop; 11 | 12 | impl Drop for HasDrop { 13 | fn drop(&mut self) { 14 | println!("Dropping!"); 15 | } 16 | } 17 | 18 | fn main() { 19 | let x = HasDrop; 20 | 21 | // Do stuff. 22 | 23 | } // `x` goes out of scope here. 24 | ``` 25 | 26 | When `x` goes out of scope at the end of `main()`, the code for `Drop` will 27 | run. `Drop` has one method, which is also called `drop()`. It takes a mutable 28 | reference to `self`. 29 | 30 | That’s it! The mechanics of `Drop` are very simple, but there are some 31 | subtleties. For example, values are dropped in the opposite order they are 32 | declared. Here’s another example: 33 | 34 | ```rust 35 | struct Firework { 36 | strength: i32, 37 | } 38 | 39 | impl Drop for Firework { 40 | fn drop(&mut self) { 41 | println!("BOOM times {}!!!", self.strength); 42 | } 43 | } 44 | 45 | fn main() { 46 | let firecracker = Firework { strength: 1 }; 47 | let tnt = Firework { strength: 100 }; 48 | } 49 | ``` 50 | 51 | This will output: 52 | 53 | ```text 54 | BOOM times 100!!! 55 | BOOM times 1!!! 56 | ``` 57 | 58 | The `tnt` goes off before the `firecracker` does, because it was declared 59 | afterwards. Last in, first out. 60 | 61 | So what is `Drop` good for? Generally, `Drop` is used to clean up any resources 62 | associated with a `struct`. For example, the [`Arc` type][arc] is a 63 | reference-counted type. When `Drop` is called, it will decrement the reference 64 | count, and if the total number of references is zero, will clean up the 65 | underlying value. 66 | 67 | [arc]: ../../std/sync/struct.Arc.html 68 | -------------------------------------------------------------------------------- /first-edition/src/effective-rust.md: -------------------------------------------------------------------------------- 1 | # Effective Rust 2 | 3 | So you’ve learned how to write some Rust code. But there’s a difference between 4 | writing *any* Rust code and writing *good* Rust code. 5 | 6 | This chapter consists of relatively independent tutorials which show you how to 7 | take your Rust to the next level. Common patterns and standard library features 8 | will be introduced. Read these sections in any order of your choosing. 9 | -------------------------------------------------------------------------------- /first-edition/src/if.md: -------------------------------------------------------------------------------- 1 | # if 2 | 3 | Rust’s take on `if` is not particularly complex, but it’s much more like the 4 | `if` you’ll find in a dynamically typed language than in a more traditional 5 | systems language. So let’s talk about it, to make sure you grasp the nuances. 6 | 7 | `if` is a specific form of a more general concept, the ‘branch’, whose name comes 8 | from a branch in a tree: a decision point, where depending on a choice, 9 | multiple paths can be taken. 10 | 11 | In the case of `if`, there is one choice that leads down two paths: 12 | 13 | ```rust 14 | let x = 5; 15 | 16 | if x == 5 { 17 | println!("x is five!"); 18 | } 19 | ``` 20 | 21 | If we changed the value of `x` to something else, this line would not print. 22 | More specifically, if the expression after the `if` evaluates to `true`, then 23 | the block is executed. If it’s `false`, then it is not. 24 | 25 | If you want something to happen in the `false` case, use an `else`: 26 | 27 | ```rust 28 | let x = 5; 29 | 30 | if x == 5 { 31 | println!("x is five!"); 32 | } else { 33 | println!("x is not five :("); 34 | } 35 | ``` 36 | 37 | If there is more than one case, use an `else if`: 38 | 39 | ```rust 40 | let x = 5; 41 | 42 | if x == 5 { 43 | println!("x is five!"); 44 | } else if x == 6 { 45 | println!("x is six!"); 46 | } else { 47 | println!("x is not five or six :("); 48 | } 49 | ``` 50 | 51 | This is all pretty standard. However, you can also do this: 52 | 53 | ```rust 54 | let x = 5; 55 | 56 | let y = if x == 5 { 57 | 10 58 | } else { 59 | 15 60 | }; // y: i32 61 | ``` 62 | 63 | Which we can (and probably should) write like this: 64 | 65 | ```rust 66 | let x = 5; 67 | 68 | let y = if x == 5 { 10 } else { 15 }; // y: i32 69 | ``` 70 | 71 | This works because `if` is an expression. The value of the expression is the 72 | value of the last expression in whichever branch was chosen. An `if` without an 73 | `else` always results in `()` as the value. 74 | -------------------------------------------------------------------------------- /first-edition/src/syntax-and-semantics.md: -------------------------------------------------------------------------------- 1 | # Syntax and Semantics 2 | 3 | This chapter breaks Rust down into small chunks, one for each concept. 4 | 5 | If you’d like to learn Rust from the bottom up, reading this in order is a 6 | great way to do that. 7 | 8 | These sections also form a reference for each concept, so if you’re reading 9 | another tutorial and find something confusing, you can find it explained 10 | somewhere in here. 11 | -------------------------------------------------------------------------------- /first-edition/src/theme/first-edition.css: -------------------------------------------------------------------------------- 1 | .warning { 2 | display: flex; 3 | justify-content: space-between; 4 | align-items: center; 5 | background-color: rgb(242, 222, 222); 6 | border-bottom-color: rgb(238, 211, 215); 7 | border-bottom-left-radius: 4px; 8 | border-bottom-right-radius: 4px; 9 | border-bottom-style: solid; 10 | border-bottom-width: 0.666667px; 11 | border-image-outset: 0 0 0 0; 12 | border-image-repeat: stretch stretch; 13 | border-image-slice: 100% 100% 100% 100%; 14 | border-image-source: none; 15 | border-image-width: 1 1 1 1; 16 | border-left-color: rgb(238, 211, 215); 17 | border-left-style: solid; 18 | border-left-width: 0.666667px; 19 | border-right-color: rgb(238, 211, 215); 20 | border-right-style: solid; 21 | border-right-width: 0.666667px; 22 | border-top-color: rgb(238, 211, 215); 23 | border-top-left-radius: 4px; 24 | border-top-right-radius: 4px; 25 | border-top-style: solid; 26 | border-top-width: 0.666667px; 27 | color: rgb(185, 74, 72); 28 | margin-bottom: 0px; 29 | margin-left: 0px; 30 | margin-right: 0px; 31 | margin-top: 30px; 32 | padding-bottom: 8px; 33 | padding-left: 14px; 34 | padding-right: 35px; 35 | padding-right: 14px; 36 | padding-top: 8px; 37 | } 38 | .warning strong { 39 | color: rgb(185, 74, 72) 40 | } 41 | .warning a { 42 | color: rgb(0, 136, 204) 43 | } 44 | .warning .message { 45 | margin-right: 14px; 46 | } 47 | .warning .message:last-child { 48 | margin-right: 21px; 49 | } 50 | .warning .button { 51 | border: none; 52 | background: none; 53 | color: inherit; 54 | cursor: pointer; 55 | font-size: 14px; 56 | } 57 | -------------------------------------------------------------------------------- /first-edition/src/theme/header.hbs: -------------------------------------------------------------------------------- 1 |
2 | You are reading an outdated edition of TRPL. For more, go here. 3 | 6 |
7 | 8 | 28 | -------------------------------------------------------------------------------- /first-edition/src/type-aliases.md: -------------------------------------------------------------------------------- 1 | # Type Aliases 2 | 3 | The `type` keyword lets you declare an alias of another type: 4 | 5 | ```rust 6 | type Name = String; 7 | ``` 8 | 9 | You can then use this type as if it were a real type: 10 | 11 | ```rust 12 | type Name = String; 13 | 14 | let x: Name = "Hello".to_string(); 15 | ``` 16 | 17 | Note, however, that this is an _alias_, not a new type entirely. In other 18 | words, because Rust is strongly typed, you’d expect a comparison between two 19 | different types to fail: 20 | 21 | ```rust,ignore 22 | let x: i32 = 5; 23 | let y: i64 = 5; 24 | 25 | if x == y { 26 | // ... 27 | } 28 | ``` 29 | 30 | this gives 31 | 32 | ```text 33 | error: mismatched types: 34 | expected `i32`, 35 | found `i64` 36 | (expected i32, 37 | found i64) [E0308] 38 | if x == y { 39 | ^ 40 | ``` 41 | 42 | But, if we had an alias: 43 | 44 | ```rust 45 | type Num = i32; 46 | 47 | let x: i32 = 5; 48 | let y: Num = 5; 49 | 50 | if x == y { 51 | // ... 52 | } 53 | ``` 54 | 55 | This compiles without error. Values of a `Num` type are the same as a value of 56 | type `i32`, in every way. You can use [tuple struct] to really get a new type. 57 | 58 | [tuple struct]: structs.html#tuple-structs 59 | 60 | You can also use type aliases with generics: 61 | 62 | ```rust 63 | use std::result; 64 | 65 | enum ConcreteError { 66 | Foo, 67 | Bar, 68 | } 69 | 70 | type Result = result::Result; 71 | ``` 72 | 73 | This creates a specialized version of the `Result` type, which always has a 74 | `ConcreteError` for the `E` part of `Result`. This is commonly used 75 | in the standard library to create custom errors for each subsection. For 76 | example, [io::Result][ioresult]. 77 | 78 | [ioresult]: ../../std/io/type.Result.html 79 | -------------------------------------------------------------------------------- /first-edition/src/using-rust-without-the-standard-library.md: -------------------------------------------------------------------------------- 1 | # Using Rust Without the Standard Library 2 | 3 | Rust’s standard library provides a lot of useful functionality, but assumes 4 | support for various features of its host system: threads, networking, heap 5 | allocation, and others. There are systems that do not have these features, 6 | however, and Rust can work with those too! To do so, we tell Rust that we 7 | don’t want to use the standard library via an attribute: `#![no_std]`. 8 | 9 | > Note: This feature is technically stable, but there are some caveats. For 10 | > one, you can build a `#![no_std]` _library_ on stable, but not a _binary_. 11 | > For details on binaries without the standard library, see [the nightly 12 | > chapter on 'lang items'][unstable book lang items] 13 | 14 | To use `#![no_std]`, add it to your crate root: 15 | 16 | ```rust,ignore 17 | #![no_std] 18 | 19 | fn plus_one(x: i32) -> i32 { 20 | x + 1 21 | } 22 | ``` 23 | 24 | Much of the functionality that’s exposed in the standard library is also 25 | available via the [`core` crate](../../core/index.html). When we’re using the 26 | standard library, Rust automatically brings `std` into scope, allowing you to 27 | use its features without an explicit import. By the same token, when using 28 | `#![no_std]`, Rust will bring `core` into scope for you, as well as [its 29 | prelude](../../core/prelude/v1/index.html). This means that a lot of code will Just 30 | Work: 31 | 32 | ```rust,ignore 33 | #![no_std] 34 | 35 | fn may_fail(failure: bool) -> Result<(), &'static str> { 36 | if failure { 37 | Err("this didn’t work!") 38 | } else { 39 | Ok(()) 40 | } 41 | } 42 | ``` 43 | 44 | [unstable book lang items]: ../../unstable-book/language-features/lang-items.html#using-libc 45 | -------------------------------------------------------------------------------- /index.md: -------------------------------------------------------------------------------- 1 | # The Rust Programming Language 2 | 3 | “The Rust Programming Language,” is an introductory book about Rust, with 4 | multiple editions. 5 | 6 | The source for all editions lives [on GitHub](https://github.com/rust-lang/book). 7 | Please open issues with any questions, concerns, or tweaks. 8 | 9 | If you're not sure what edition you want to read, Go with the [second 10 | edition](second-edition/index.html), as it's the most polished. 11 | 12 | ## Second Edition 13 | 14 | The second edition is still receiving some minor edits, but is effectively 15 | complete. It will be [available in dead-tree form through NoStarch 16 | Press](https://nostarch.com/Rust) once these final edits are complete. 17 | 18 | The second edition is a complete re-write of TRPL, from the ground up, 19 | and is therefore very different from the first edition. It's also based 20 | on Rust 1.21, and so may be missing features that landed in stable after 21 | that release. 22 | 23 | You can find the second edition [here](second-edition/index.html). 24 | 25 | ### First Edition 26 | 27 | The first edition is completely frozen, but is still included in the 28 | documentation for historical reasons. 29 | 30 | You can find the first edition [here](first-edition/index.html). -------------------------------------------------------------------------------- /redirects/README.md: -------------------------------------------------------------------------------- 1 | % The Rust Programming Language 2 | 3 | There are two editions of "The Rust Programming Language": 4 | 5 | * [First edition](first-edition/index.html) 6 | * [Second edition](second-edition/index.html) 7 | 8 | The second edition is a complete re-write. It is still under construction; 9 | though it is far enough along to learn most of Rust; we suggest reading the 10 | second edition and then checking out the first edition later to pick up some of 11 | the more esoteric parts of the language. 12 | -------------------------------------------------------------------------------- /redirects/SUMMARY.md: -------------------------------------------------------------------------------- 1 | % The Rust Programming Language 2 | 3 | There are two editions of "The Rust Programming Language": 4 | 5 | * [First edition](first-edition/index.html) 6 | * [Second edition](second-edition/index.html) 7 | 8 | The second edition is a complete re-write. It is still under construction; 9 | though it is far enough along to learn most of Rust; we suggest reading the 10 | second edition and then checking out the first edition later to pick up some of 11 | the more esoteric parts of the language. 12 | -------------------------------------------------------------------------------- /redirects/associated-types.md: -------------------------------------------------------------------------------- 1 | % Associated Types 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > Associated types are a way of associating a type placeholder with a trait such that the trait method definitions can use these placeholder types in their signatures. 6 | 7 | ```rust 8 | pub trait Iterator { 9 | type Item; 10 | fn next(&mut self) -> Option; 11 | } 12 | ``` 13 | 14 | --- 15 | 16 | Here are the relevant sections in the new and old books: 17 | 18 | * **[In the second edition: Ch 19.03 — Advanced Traits][2]** 19 | * [In the first edition: Ch 3.30 — Associated Types][1] 20 | 21 | 22 | [1]: first-edition/associated-types.html 23 | [2]: second-edition/ch19-03-advanced-traits.html#associated-types-specify-placeholder-types-in-trait-definitions 24 | -------------------------------------------------------------------------------- /redirects/attributes.md: -------------------------------------------------------------------------------- 1 | % Attributes 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > Any item declaration may have an attribute applied to it. 6 | 7 | ```rust 8 | // A function marked as a unit test 9 | #[test] 10 | fn test_foo() { 11 | /* ... */ 12 | } 13 | ``` 14 | 15 | --- 16 | 17 | Here are the relevant sections in the new and old books: 18 | 19 | * **[In the Rust Reference: Ch 5.3 — Attributes][2]** 20 | * [In the first edition: Ch 3.27 — Attributes][1] 21 | 22 | 23 | [1]: first-edition/attributes.html 24 | [2]: ../reference/attributes.html 25 | -------------------------------------------------------------------------------- /redirects/bibliography.md: -------------------------------------------------------------------------------- 1 | % Bibliography 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | This page does not exist in [the second edition][2]. 6 | You might be interested in a similar page in [the Rust Reference][3]. 7 | 8 | * **[In the Rust Reference: Appendix — Influences][3]** 9 | * [In the first edition: Section 7 — Bibliography][1] 10 | 11 | 12 | [1]: first-edition/bibliography.html 13 | [2]: second-edition/index.html 14 | [3]: ../reference/influences.html 15 | -------------------------------------------------------------------------------- /redirects/borrow-and-asref.md: -------------------------------------------------------------------------------- 1 | % Borrow and AsRef 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > A cheap reference-to-reference conversion. 6 | > Used to convert a value to a reference value within generic code. 7 | 8 | ```rust 9 | fn is_hello>(s: T) { 10 | assert_eq!("hello", s.as_ref()); 11 | } 12 | ``` 13 | 14 | --- 15 | 16 | This chapter does not exist in [the second edition][2]. 17 | The best place to learn more about this is [the Rust documentation][3]. 18 | 19 | * **[In the Rust documentation: `convert::AsRef`][3]** 20 | * [In the first edition: Ch 4.10 — Borrow and AsRef][1] 21 | 22 | 23 | [1]: first-edition/borrow-and-asref.html 24 | [2]: second-edition/index.html 25 | [3]: ../std/convert/trait.AsRef.html 26 | -------------------------------------------------------------------------------- /redirects/casting-between-types.md: -------------------------------------------------------------------------------- 1 | % Casting between types 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > A type cast expression is denoted with the binary operator `as`. 6 | > Executing an `as` expression casts the value on the left-hand side to the type on the right-hand side. 7 | 8 | ```rust 9 | # fn sum(values: &[f64]) -> f64 { 0.0 } 10 | # fn len(values: &[f64]) -> i32 { 0 } 11 | 12 | fn average(values: &[f64]) -> f64 { 13 | let sum: f64 = sum(values); 14 | let size: f64 = len(values) as f64; 15 | sum / size 16 | } 17 | ``` 18 | 19 | --- 20 | 21 | Here are the relevant sections in the new and old books: 22 | 23 | * **[In the second edition: Appendix A — Keywords][2]** 24 | * [In the Rust Reference: Type Cast Expressions][3] 25 | * [In the Rust documentation: `mem::transmute`][4] 26 | * [In the first edition: Ch 3.29 — Casting between types][1] 27 | 28 | 29 | [1]: first-edition/casting-between-types.html 30 | [2]: second-edition/appendix-01-keywords.html 31 | [3]: ../reference/expressions/operator-expr.html#type-cast-expressions 32 | [4]: ../std/mem/fn.transmute.html -------------------------------------------------------------------------------- /redirects/choosing-your-guarantees.md: -------------------------------------------------------------------------------- 1 | % Choosing your Guarantees 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > Smart pointers are data structures that act like a pointer, but they also have additional metadata and capabilities. 6 | > The different smart pointers defined in Rust’s standard library provide extra functionality beyond what references provide. 7 | 8 | ```rust 9 | let b = Box::new(5); 10 | println!("b = {}", b); 11 | ``` 12 | 13 | --- 14 | 15 | Here are the relevant sections in the new and old books: 16 | 17 | * **[In the second edition: Ch 15.00 — Smart Pointers][2]** 18 | * [In the first edition: Ch 4.8 — Choosing your Guarantees][1] 19 | 20 | 21 | [1]: first-edition/choosing-your-guarantees.html 22 | [2]: second-edition/ch15-00-smart-pointers.html 23 | -------------------------------------------------------------------------------- /redirects/closures.md: -------------------------------------------------------------------------------- 1 | % Closures 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > Anonymous functions you can save in a variable or pass as arguments to other functions. 6 | 7 | ```rust 8 | # use std::thread; 9 | # use std::time::Duration; 10 | 11 | let expensive_closure = |num| { 12 | println!("calculating slowly..."); 13 | thread::sleep(Duration::from_secs(2)); 14 | num 15 | }; 16 | # expensive_closure(5); 17 | ``` 18 | 19 | --- 20 | 21 | Here are the relevant sections in the new and old books: 22 | 23 | * **[In the second edition: Ch 13.01 — Closures][2]** 24 | * [In the first edition: Ch 3.23 — Closures][1] 25 | 26 | 27 | [1]: first-edition/closures.html 28 | [2]: second-edition/ch13-01-closures.html 29 | -------------------------------------------------------------------------------- /redirects/comments.md: -------------------------------------------------------------------------------- 1 | % Comments 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > Comments must start with two slashes and continue until the end of the line. 6 | > For comments that extend beyond a single line, you’ll need to include // on each line. 7 | 8 | ```rust 9 | // So we’re doing something complicated here, long enough that we need 10 | // multiple lines of comments to do it! Whew! Hopefully, this comment will 11 | // explain what’s going on. 12 | ``` 13 | 14 | --- 15 | 16 | Here are the relevant sections in the new and old books: 17 | 18 | * **[In the second edition: Ch 3.04 — Comments][2]** 19 | * [In the first edition: Ch 3.4 — Comments][1] 20 | 21 | 22 | [1]: first-edition/comments.html 23 | [2]: second-edition/ch03-04-comments.html 24 | -------------------------------------------------------------------------------- /redirects/compiler-plugins.md: -------------------------------------------------------------------------------- 1 | % Compiler Plugins 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > Compiler plugins are user-provided libraries that extend the compiler's behavior with new syntax extensions, lint checks, etc. 6 | 7 | --- 8 | 9 | This particular chapter has moved to [the Unstable Book][2]. 10 | 11 | * **[In the Unstable Rust Book: `plugin`][2]** 12 | 13 | [2]: ../unstable-book/language-features/plugin.html 14 | -------------------------------------------------------------------------------- /redirects/concurrency.md: -------------------------------------------------------------------------------- 1 | % Concurrency 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > Historically, programming [concurrency] has been difficult and error prone: Rust hopes to change that. 6 | > Fearless concurrency allows you to write code that’s free of subtle bugs and is easy to refactor without introducing new bugs. 7 | 8 | --- 9 | 10 | Here are the relevant sections in the new and old books: 11 | 12 | * **[In the second edition: Ch 16.00 — Fearless Concurrency][2]** 13 | * [In the first edition: Ch 4.6 — Concurrency][1] 14 | 15 | 16 | [1]: first-edition/concurrency.html 17 | [2]: second-edition/ch16-00-concurrency.html 18 | -------------------------------------------------------------------------------- /redirects/conditional-compilation.md: -------------------------------------------------------------------------------- 1 | % Conditional Compilation 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > Sometimes one wants to have different compiler outputs from the same code, depending on build target, such as targeted operating system, or to enable release builds. 6 | > Configuration options are either provided by the compiler or passed in on the command line using. 7 | > Rust code then checks for their presence using the `#[cfg(...)]` attribute 8 | 9 | ```rust 10 | // The function is only included in the build when compiling for macOS 11 | #[cfg(target_os = "macos")] 12 | fn macos_only() { 13 | // ... 14 | } 15 | ``` 16 | 17 | --- 18 | 19 | This particular chapter does not exist in [the second edition][2]. 20 | The best place to learn about it is [the Rust Reference][3]. 21 | 22 | * **[In the Rust Reference: Ch 5.3 — Attributes, Conditional Compilation section][3]** 23 | * [In the first edition: Ch 4.3 — Conditional Compilation][1] 24 | 25 | 26 | [1]: first-edition/conditional-compilation.html 27 | [2]: second-edition/index.html 28 | [3]: ../reference/attributes.html#conditional-compilation 29 | -------------------------------------------------------------------------------- /redirects/const-and-static.md: -------------------------------------------------------------------------------- 1 | % `const` and `static` 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > Constants are _always_ immutable, and may only be set to a constant expression, not the result of a function call or any other value that could only be computed at runtime. 6 | > 7 | > Global variables are called `static` in Rust. 8 | 9 | ```rust 10 | const MAX_POINTS: u32 = 100_000; 11 | static HELLO_WORLD: &str = "Hello, world!"; 12 | ``` 13 | 14 | --- 15 | 16 | Here are the relevant sections in the new and old books: 17 | 18 | * **[In the second edition: Ch 3.01 — Variables and Mutability, section Constants][2]** 19 | * **[In the second edition: Ch 19.01 — Unsafe Rust, section Static Variables][3]** 20 | * [In the first edition: Ch 3.26 — `const` and `static`][1] 21 | 22 | 23 | [1]: first-edition/const-and-static.html 24 | [2]: second-edition/ch03-01-variables-and-mutability.html#differences-between-variables-and-constants 25 | [3]: second-edition/ch19-01-unsafe-rust.html#accessing-or-modifying-a-mutable-static-variable 26 | -------------------------------------------------------------------------------- /redirects/crates-and-modules.md: -------------------------------------------------------------------------------- 1 | % Crates and Modules 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > Rust has a module system that enables the reuse of code in an organized fashion. 6 | > A module is a namespace that contains definitions of functions or types, and you can choose whether those definitions are visible outside their module (public) or not (private). 7 | > 8 | > A crate is a project that other people can pull into their projects as a dependency. 9 | 10 | ```rust 11 | mod network { 12 | fn connect() { 13 | } 14 | } 15 | ``` 16 | 17 | --- 18 | 19 | Here are the relevant sections in the new and old books: 20 | 21 | * **[In the second edition: Ch 7.01 — `mod` and the Filesystem][2]** 22 | * [In the second edition: Ch 14.02 — Publishing a Crate to Crates.io][2] 23 | * [In the first edition: Ch 3.25 — Crates and Modules][1] 24 | 25 | 26 | [1]: first-edition/crates-and-modules.html 27 | [2]: second-edition/ch07-01-mod-and-the-filesystem.html 28 | [3]: second-edition/ch14-02-publishing-to-crates-io.html 29 | -------------------------------------------------------------------------------- /redirects/deref-coercions.md: -------------------------------------------------------------------------------- 1 | % Deref coercions 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > Implementing the `Deref` trait allows us to customize the behavior of the _dereference operator_ `*`. 6 | > By implementing `Deref` in such a way that a smart pointer can be treated like a regular reference, we can write code that operates on references and use that code with smart pointers too. 7 | 8 | ```rust 9 | use std::ops::Deref; 10 | 11 | # struct MyBox(T); 12 | impl Deref for MyBox { 13 | type Target = T; 14 | 15 | fn deref(&self) -> &T { 16 | &self.0 17 | } 18 | } 19 | ``` 20 | 21 | --- 22 | 23 | Here are the relevant sections in the new and old books: 24 | 25 | * **[In the second edition: Ch 15.02 — Treating Smart Pointers like Regular References with the `Deref` Trait][2]** 26 | * [In the first edition: Ch 3.33 — Deref coercions][1] 27 | 28 | 29 | [1]: first-edition/deref-coercions.html 30 | [2]: second-edition/ch15-02-deref.html 31 | -------------------------------------------------------------------------------- /redirects/documentation.md: -------------------------------------------------------------------------------- 1 | % Documentation 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > Documentation comments use `///` instead of `//` and support Markdown notation for formatting the text if you’d like. 6 | > You place documentation comments just before the item they are documenting. 7 | 8 | ```rust,no_run 9 | /// Adds one to the number given. 10 | /// 11 | /// # Examples 12 | /// 13 | /// ``` 14 | /// let five = 5; 15 | /// 16 | /// assert_eq!(6, my_crate::add_one(5)); 17 | /// ``` 18 | pub fn add_one(x: i32) -> i32 { 19 | x + 1 20 | } 21 | ``` 22 | 23 | --- 24 | 25 | Here are the relevant sections in the new and old books: 26 | 27 | * **[In the second edition: Ch 14.02 — Publishing to crates.io, section Making useful documentation][2]** 28 | * [In the first edition: Ch 4.4 — Documentation][1] 29 | 30 | 31 | [1]: first-edition/documentation.html 32 | [2]: second-edition/ch14-02-publishing-to-crates-io.html#making-useful-documentation-comments 33 | -------------------------------------------------------------------------------- /redirects/drop.md: -------------------------------------------------------------------------------- 1 | % Drop 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > `Drop` lets us customize what happens when a value is about to go out of scope. 6 | 7 | ```rust 8 | struct CustomSmartPointer { 9 | data: String, 10 | } 11 | 12 | impl Drop for CustomSmartPointer { 13 | fn drop(&mut self) { 14 | println!("Dropping CustomSmartPointer with data `{}`!", self.data); 15 | } 16 | } 17 | 18 | fn main() { 19 | let c = CustomSmartPointer { data: String::from("my stuff") }; 20 | let d = CustomSmartPointer { data: String::from("other stuff") }; 21 | println!("CustomSmartPointers created."); 22 | } 23 | ``` 24 | 25 | --- 26 | 27 | Here are the relevant sections in the new and old books: 28 | 29 | * **[In the second edition: Ch 15.03 — The `Drop` Trait Runs Code on Cleanup][2]** 30 | * [In the first edition: Ch 3.20 — Drop][1] 31 | 32 | 33 | [1]: first-edition/drop.html 34 | [2]: second-edition/ch15-03-drop.html 35 | -------------------------------------------------------------------------------- /redirects/effective-rust.md: -------------------------------------------------------------------------------- 1 | % Effective Rust 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | This section does not exist in [the second edition][2]. 6 | However, the second edition encourages writing effective Rust from the start. 7 | It is recommended to start there. 8 | 9 | * **[The second edition of The Rust Programming Language][2]** 10 | * [In the first edition: Ch 4 — Effective Rust][1] 11 | 12 | 13 | [1]: first-edition/effective-rust.html 14 | [2]: second-edition/index.html 15 | -------------------------------------------------------------------------------- /redirects/enums.md: -------------------------------------------------------------------------------- 1 | % Enums 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > Enums allow you to define a type by enumerating its possible values. 6 | 7 | ```rust 8 | enum IpAddrKind { 9 | V4, 10 | V6, 11 | } 12 | ``` 13 | 14 | --- 15 | 16 | Here are the relevant sections in the new and old books: 17 | 18 | * **[In the second edition: Ch 6.01 — Defining an Enum][2]** 19 | * [In the first edition: Ch 3.13 — Enums][1] 20 | 21 | 22 | [1]: first-edition/enums.html 23 | [2]: second-edition/ch06-01-defining-an-enum.html 24 | -------------------------------------------------------------------------------- /redirects/error-handling.md: -------------------------------------------------------------------------------- 1 | % Error Handling 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > Rust groups errors into two major categories: _recoverable_ errors with `Result` and _unrecoverable_ errors with `panic!`. 6 | 7 | --- 8 | 9 | Here are the relevant sections in the new and old books: 10 | 11 | * **[In the second edition: Ch 9.00 — Error Handling][2]** 12 | * [In the first edition: Ch 4.7 — Error Handling][1] 13 | 14 | 15 | [1]: first-edition/error-handling.html 16 | [2]: second-edition/ch09-00-error-handling.html 17 | -------------------------------------------------------------------------------- /redirects/ffi.md: -------------------------------------------------------------------------------- 1 | % FFI 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > Sometimes, your Rust code may need to interact with code written in another language. 6 | > To do this, Rust has a keyword, `extern`, that facilitates creating and using a _Foreign Function Interface_ (FFI). 7 | 8 | ```rust 9 | extern "C" { 10 | fn abs(input: i32) -> i32; 11 | } 12 | 13 | fn main() { 14 | unsafe { 15 | println!("Absolute value of -3 according to C: {}", abs(-3)); 16 | } 17 | } 18 | ``` 19 | 20 | --- 21 | 22 | Here are the relevant sections in the new and old books: 23 | 24 | * **[In the second edition: Ch 19.01 — Unsafe Rust, section `extern` functions][2]** 25 | * [In the first edition: Ch 4.9 — FFI][1] 26 | 27 | 28 | [1]: first-edition/ffi.html 29 | [2]: second-edition/ch19-01-unsafe-rust.html#using-extern-functions-to-call-external-code 30 | -------------------------------------------------------------------------------- /redirects/functions.md: -------------------------------------------------------------------------------- 1 | % Functions 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > Function definitions in Rust start with `fn` and have a set of parentheses after the function name. 6 | > The curly brackets tell the compiler where the function body begins and ends. 7 | > We can call any function we’ve defined by entering its name followed by a set of parentheses. 8 | 9 | ```rust 10 | fn main() { 11 | println!("Hello, world!"); 12 | 13 | another_function(); 14 | } 15 | 16 | fn another_function() { 17 | println!("Another function."); 18 | } 19 | ``` 20 | 21 | --- 22 | 23 | Here are the relevant sections in the new and old books: 24 | 25 | * **[In the first edition: Ch 3.2 — Functions][1]** 26 | * [In the second edition: Ch 3.03 — Functions][2] 27 | 28 | 29 | [1]: first-edition/functions.html 30 | [2]: second-edition/ch03-03-how-functions-work.html 31 | -------------------------------------------------------------------------------- /redirects/generics.md: -------------------------------------------------------------------------------- 1 | % Generics 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > Generics are abstract stand-ins for concrete types or other properties. 6 | 7 | ```rust 8 | struct Point { 9 | x: T, 10 | y: U, 11 | } 12 | 13 | fn main() { 14 | let both_integer = Point { x: 5, y: 10 }; 15 | let both_float = Point { x: 1.0, y: 4.0 }; 16 | let integer_and_float = Point { x: 5, y: 4.0 }; 17 | } 18 | ``` 19 | 20 | --- 21 | 22 | Here are the relevant sections in the new and old books: 23 | 24 | * **[In the second edition: Ch 10.00 — Generic Types, Traits, and Lifetimes][2]** 25 | * [In the first edition: Ch 3.18 — Generics][1] 26 | 27 | 28 | [1]: first-edition/generics.html 29 | [2]: second-edition/ch10-00-generics.html 30 | 31 | -------------------------------------------------------------------------------- /redirects/getting-started.md: -------------------------------------------------------------------------------- 1 | % Getting Started 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | You can [continue to the exact older page][1]. 6 | If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. 7 | 8 | * **[In the second edition: Getting Started][2]** 9 | * [In the first edition: Getting Started][1] 10 | 11 | 12 | [1]: first-edition/getting-started.html 13 | [2]: second-edition/ch01-00-getting-started.html 14 | -------------------------------------------------------------------------------- /redirects/glossary.md: -------------------------------------------------------------------------------- 1 | % Glossary 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | This section does not exist in [the second edition][2]. 6 | However, the second edition defines the terms it uses inline, rather than using a glossary. 7 | It is recommended to start there. 8 | 9 | * **[The second edition of The Rust Programming Language][2]** 10 | * [In the first edition: Glossary][1] 11 | 12 | 13 | [1]: first-edition/glossary.html 14 | [2]: second-edition/index.html 15 | -------------------------------------------------------------------------------- /redirects/guessing-game.md: -------------------------------------------------------------------------------- 1 | % Tutorial: Guessing Game 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. 6 | 7 | * **[In the first edition: Tutorial — Guessing Game][1]** 8 | * [In the second edition: Ch 2.00 — Guessing Game tutorial][2] 9 | 10 | 11 | [1]: first-edition/guessing-game.html 12 | [2]: second-edition/ch02-00-guessing-game-tutorial.html 13 | -------------------------------------------------------------------------------- /redirects/if-let.md: -------------------------------------------------------------------------------- 1 | % if let 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > The `if let` syntax lets you combine `if` and `let` into a less verbose way to handle values that match one pattern and ignore the rest. 6 | 7 | ```rust 8 | let some_u8_value = Some(3u8); 9 | if let Some(3) = some_u8_value { 10 | println!("three"); 11 | } 12 | ``` 13 | 14 | --- 15 | 16 | Here are the relevant sections in the new and old books: 17 | 18 | * **[In the second edition: Ch 6.03 — Concise Control Flow with `if let`][2]** 19 | * [In the first edition: Ch 3.21 — if let][1] 20 | 21 | 22 | [1]: first-edition/if-let.html 23 | [2]: second-edition/ch06-03-if-let.html 24 | -------------------------------------------------------------------------------- /redirects/if.md: -------------------------------------------------------------------------------- 1 | % if 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > An `if` expression allows us to branch our code depending on conditions. 6 | 7 | ```rust 8 | fn main() { 9 | let number = 3; 10 | 11 | if number < 5 { 12 | println!("condition was true"); 13 | } else { 14 | println!("condition was false"); 15 | } 16 | } 17 | ``` 18 | 19 | --- 20 | 21 | Here are the relevant sections in the new and old books: 22 | 23 | * **[In the second edition: Ch 3.05 — Control flow][2]** 24 | * [In the first edition: Ch 3.5 — if][1] 25 | 26 | 27 | [1]: first-edition/if.html 28 | [2]: second-edition/ch03-05-control-flow.html#if-expressions 29 | -------------------------------------------------------------------------------- /redirects/iterators.md: -------------------------------------------------------------------------------- 1 | % Iterators 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > The iterator pattern allows you to perform some task on a sequence of items in turn. 6 | > An iterator is responsible for the logic of iterating over each item and determining when the sequence has finished. 7 | 8 | ```rust 9 | let v1 = vec![1, 2, 3]; 10 | 11 | let v1_iter = v1.iter(); 12 | 13 | for val in v1_iter { 14 | println!("Got: {}", val); 15 | } 16 | ``` 17 | 18 | --- 19 | 20 | Here are the relevant sections in the new and old books: 21 | 22 | * **[In the second edition: Ch 13.02 — Iterators][2]** 23 | * [In the first edition: Ch 4.5 — Iterators][1] 24 | 25 | 26 | [1]: first-edition/iterators.html 27 | [2]: second-edition/ch13-02-iterators.html 28 | -------------------------------------------------------------------------------- /redirects/lifetimes.md: -------------------------------------------------------------------------------- 1 | % Lifetimes 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > Every reference in Rust has a lifetime, which is the scope for which that reference is valid. 6 | > Most of the time lifetimes are implicit and inferred. 7 | 8 | ```rust 9 | { 10 | let x = 5; // -----+-- 'b 11 | // | 12 | let r = &x; // --+--+-- 'a 13 | // | | 14 | println!("r: {}", r); // | | 15 | // --+ | 16 | } // -----+ 17 | ``` 18 | 19 | --- 20 | 21 | Here are the relevant sections in the new and old books: 22 | 23 | * **[In the second edition: Ch 10.03 — Lifetimes][2]** 24 | * [In the second edition: Ch 19.02 — Advanced Lifetimes][3] 25 | * [In the first edition: Ch 3.10 — Lifetimes][1] 26 | 27 | 28 | [1]: first-edition/lifetimes.html 29 | [2]: second-edition/ch10-03-lifetime-syntax.html 30 | [3]: second-edition/ch19-02-advanced-lifetimes.html 31 | -------------------------------------------------------------------------------- /redirects/loops.md: -------------------------------------------------------------------------------- 1 | % Loops 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > Rust has three kinds of loops: `loop`, `while`, and `for`. 6 | > The `loop` keyword tells Rust to execute a block of code over and over again forever or until you explicitly tell it to stop. 7 | > `while` loops evaluate a block of code until a condition ceases to be true. 8 | > A `for` loop executes some code for each item in a collection. 9 | 10 | ```rust,no_run 11 | loop { 12 | println!("again!"); 13 | } 14 | 15 | let mut number = 3; 16 | while number != 0 { 17 | println!("{}!", number); 18 | number = number - 1; 19 | } 20 | 21 | let a = [10, 20, 30, 40, 50]; 22 | for element in a.iter() { 23 | println!("the value is: {}", element); 24 | } 25 | ``` 26 | 27 | --- 28 | 29 | Here are the relevant sections in the new and old books: 30 | 31 | * **[In the second edition: Ch 3.05 — Control flow][2]** 32 | * [In the first edition: Ch 3.6 — Loops][1] 33 | 34 | 35 | [1]: first-edition/loops.html 36 | [2]: second-edition/ch03-05-control-flow.html#repetition-with-loops 37 | -------------------------------------------------------------------------------- /redirects/macros.md: -------------------------------------------------------------------------------- 1 | % Macros 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > While functions and types abstract over code, macros abstract at a syntactic level. 6 | 7 | ```rust 8 | macro_rules! five_times { 9 | ($x:expr) => (5 * $x); 10 | } 11 | 12 | fn main() { 13 | assert_eq!(25, five_times!(2 + 3)); 14 | } 15 | ``` 16 | 17 | --- 18 | 19 | Here are the relevant sections in the new and old books: 20 | 21 | * **[In the second edition: Appendix D — Macros][2]** 22 | * [Rust By Example: Macros][3] 23 | * [In the Rust Reference: Ch 3.1 — Macros by Example][4] 24 | * [In the first edition: Ch 3.34 — Macros][1] 25 | 26 | 27 | [1]: first-edition/macros.html 28 | [2]: second-edition/appendix-04-macros.html 29 | [3]: https://rustbyexample.com/macros.html 30 | [4]: ../reference/macros-by-example.html 31 | -------------------------------------------------------------------------------- /redirects/match.md: -------------------------------------------------------------------------------- 1 | % Match 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > `match` allows us to compare a value against a series of patterns and then execute code based on which pattern matches. 6 | > Patterns can be made up of literal values, variable names, wildcards, and many other things. 7 | 8 | ```rust 9 | enum Coin { 10 | Penny, 11 | Nickel, 12 | Dime, 13 | Quarter, 14 | } 15 | 16 | fn value_in_cents(coin: Coin) -> u32 { 17 | match coin { 18 | Coin::Penny => 1, 19 | Coin::Nickel => 5, 20 | Coin::Dime => 10, 21 | Coin::Quarter => 25, 22 | } 23 | } 24 | ``` 25 | 26 | --- 27 | 28 | Here are the relevant sections in the new and old books: 29 | 30 | * **[In the second edition: Ch 6.02 — The `match` Control Flow Operator][2]** 31 | * [In the second edition: Ch 18.00 — Patterns][3] 32 | * [In the first edition: Ch 3.14 — Match][1] 33 | 34 | 35 | [1]: first-edition/match.html 36 | [2]: second-edition/ch06-02-match.html 37 | [3]: second-edition/ch18-00-patterns.html 38 | 39 | -------------------------------------------------------------------------------- /redirects/method-syntax.md: -------------------------------------------------------------------------------- 1 | % Method Syntax 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > Methods are different from functions in that they’re defined within the context of a struct, and their first parameter is always `self`, which represents the instance of the struct the method is being called on. 6 | 7 | ```rust 8 | # struct Rectangle { 9 | # width: u32, 10 | # height: u32, 11 | # } 12 | 13 | impl Rectangle { 14 | fn area(&self) -> u32 { 15 | self.width * self.height 16 | } 17 | } 18 | ``` 19 | 20 | --- 21 | 22 | Here are the relevant sections in the new and old books: 23 | 24 | * **[In the second edition: Ch 5.03 — Method Syntax][2]** 25 | * [In the first edition: Ch 3.16 — Method Syntax][1] 26 | 27 | 28 | [1]: first-edition/method-syntax.html 29 | [2]: second-edition/ch05-03-method-syntax.html 30 | -------------------------------------------------------------------------------- /redirects/mutability.md: -------------------------------------------------------------------------------- 1 | % Mutability 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > Variables are immutable only by default; we can make them mutable by adding mut in front of the variable name. 6 | 7 | ```rust 8 | let mut x = 5; 9 | println!("The value of x is: {}", x); 10 | x = 6; 11 | println!("The value of x is: {}", x); 12 | ``` 13 | 14 | --- 15 | 16 | Here are the relevant sections in the new and old books: 17 | 18 | * **[In the second edition: Ch 3.01 — Variables and Mutability][2]** 19 | * [In the first edition: Ch 3.11 — Mutability][1] 20 | 21 | 22 | [1]: first-edition/mutability.html 23 | [2]: second-edition/ch03-01-variables-and-mutability.html 24 | -------------------------------------------------------------------------------- /redirects/operators-and-overloading.md: -------------------------------------------------------------------------------- 1 | % Operators and Overloading 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > Rust does not allow you to create your own operators or overload arbitrary operators, but the operations and corresponding traits listed in `std::ops` can be overloaded by implementing the traits associated with the operator. 6 | 7 | ```rust 8 | use std::ops::Add; 9 | 10 | #[derive(Debug,PartialEq)] 11 | struct Point { 12 | x: i32, 13 | y: i32, 14 | } 15 | 16 | impl Add for Point { 17 | type Output = Point; 18 | 19 | fn add(self, other: Point) -> Point { 20 | Point { 21 | x: self.x + other.x, 22 | y: self.y + other.y, 23 | } 24 | } 25 | } 26 | 27 | fn main() { 28 | assert_eq!(Point { x: 1, y: 0 } + Point { x: 2, y: 3 }, 29 | Point { x: 3, y: 3 }); 30 | } 31 | ``` 32 | 33 | --- 34 | 35 | Here are the relevant sections in the new and old books: 36 | 37 | * **[In the second edition: Ch 19.03 — Advanced Traits, section Operator Overloading][2]** 38 | * [In the Rust documentation: `std::ops`][3] 39 | * [In the first edition: Ch 3.32 — Operators and Overloading][1] 40 | 41 | [1]: first-edition/operators-and-overloading.html 42 | [2]: second-edition/ch19-03-advanced-traits.html#default-generic-type-parameters-and-operator-overloading 43 | [3]: ../std/ops/index.html 44 | -------------------------------------------------------------------------------- /redirects/ownership.md: -------------------------------------------------------------------------------- 1 | % Ownership 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > Ownership is Rust’s most unique feature, and it enables Rust to make memory safety guarantees without needing a garbage collector. 6 | > 7 | > 1. Each value in Rust has a variable that’s called its _owner_. 8 | > 2. There can only be one owner at a time. 9 | > 3. When the owner goes out of scope, the value will be dropped. 10 | 11 | --- 12 | 13 | Here are the relevant sections in the new and old books: 14 | 15 | * **[In the second edition: Ch 4.00 — Understanding Ownership][2]** 16 | * [In the first edition: Ch 3.8 — Ownership][1] 17 | 18 | 19 | [1]: first-edition/ownership.html 20 | [2]: second-edition/ch04-00-understanding-ownership.html 21 | -------------------------------------------------------------------------------- /redirects/patterns.md: -------------------------------------------------------------------------------- 1 | % Patterns 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > Patterns are a special syntax within Rust for matching against the structure of our types, complex or simple. 6 | > A pattern is made up of some combination of literals; destructured arrays, enums, structs, or tuples; variables, wildcards, and placeholders. 7 | > These pieces describe the “shape” of the data we’re working with. 8 | 9 | ```rust 10 | let x = Some(5); 11 | let y = 10; 12 | 13 | match x { 14 | Some(50) => println!("Got 50"), 15 | Some(y) => println!("Matched, y = {:?}", y), 16 | _ => println!("Default case, x = {:?}", x), 17 | } 18 | ``` 19 | 20 | --- 21 | 22 | Here are the relevant sections in the new and old books: 23 | 24 | * **[In the second edition: Ch 18.03 — Patterns][2]** 25 | * [In the second edition: Ch 6.02 — Match][3] 26 | * [In the first edition: Ch 3.15 — Patterns][1] 27 | 28 | 29 | [1]: first-edition/patterns.html 30 | [2]: second-edition/ch18-00-patterns.html 31 | [3]: second-edition/ch06-02-match.html#patterns-that-bind-to-values 32 | -------------------------------------------------------------------------------- /redirects/primitive-types.md: -------------------------------------------------------------------------------- 1 | % Primitive Types 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > Rust is a _statically typed_ language, which means that it must know the types of all variables at compile time. 6 | > The compiler can usually infer what type we want to use based on the value and how we use it. 7 | > In cases when many types are possible, a _type annotation_ must be added. 8 | 9 | ```rust 10 | let x = 2.0; // f64 11 | 12 | let y: f32 = 3.0; // f32 13 | ``` 14 | 15 | --- 16 | 17 | Here are the relevant sections in the new and old books: 18 | 19 | * **[In the second edition: Ch 3.02 — Data Types][2]** 20 | * [In the first edition: Ch 3.3 — Primitive Types][1] 21 | 22 | 23 | [1]: first-edition/primitive-types.html 24 | [2]: second-edition/ch03-02-data-types.html 25 | -------------------------------------------------------------------------------- /redirects/procedural-macros.md: -------------------------------------------------------------------------------- 1 | % Procedural Macros (and custom Derive) 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > Procedural macros allow for all sorts of advanced metaprogramming in Rust. 6 | 7 | --- 8 | 9 | This chapter does not exist yet in [the second edition][2]. 10 | You can check out other resources that describe macros. 11 | 12 | * **[In the Rust Reference: Ch 3.2 — Procedural Macros][4]** 13 | * [The `proc_macro` crate documentation][3] 14 | * [In the second edition: (future) Appendix D — Macros][2] 15 | * [In the first edition: Ch 4.13 — Procedural Macros (and custom Derive)][1] 16 | 17 | 18 | [1]: first-edition/procedural-macros.html 19 | [2]: second-edition/appendix-04-macros.html 20 | [3]: ../proc_macro/index.html 21 | [4]: ../reference/procedural-macros.html -------------------------------------------------------------------------------- /redirects/raw-pointers.md: -------------------------------------------------------------------------------- 1 | % Raw Pointers 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > Raw pointers are allowed to ignore many of the rules that references have to follow. 6 | 7 | ```rust 8 | let mut num = 5; 9 | 10 | let r1 = &num as *const i32; 11 | let r2 = &mut num as *mut i32; 12 | ``` 13 | 14 | --- 15 | 16 | Here are the relevant sections in the new and old books: 17 | 18 | * **[In the second edition: Ch 19.01 — Unsafe Rust, section Dereferencing a Raw Pointer][2]** 19 | * [In the first edition: Ch 3.35 — Raw Pointers][1] 20 | 21 | 22 | [1]: first-edition/raw-pointers.html 23 | [2]: second-edition/ch19-01-unsafe-rust.html#dereferencing-a-raw-pointer 24 | -------------------------------------------------------------------------------- /redirects/references-and-borrowing.md: -------------------------------------------------------------------------------- 1 | % References and Borrowing 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > A reference _refers_ to a value but does not own it. 6 | > Because it does not own it, the value it points to will not be dropped when the reference goes out of scope. 7 | 8 | ```rust 9 | fn calculate_length(s: &String) -> usize { // s is a reference to a String 10 | s.len() 11 | } // Here, s goes out of scope. But because it does not have ownership of what 12 | // it refers to, nothing happens. 13 | ``` 14 | 15 | --- 16 | 17 | Here are the relevant sections in the new and old books: 18 | 19 | * **[In the second edition: Ch 4.02 — References and Borrowing][2]** 20 | * [In the first edition: Ch 3.9 — References and Borrowing][1] 21 | 22 | 23 | [1]: first-edition/references-and-borrowing.html 24 | [2]: second-edition/ch04-02-references-and-borrowing.html 25 | -------------------------------------------------------------------------------- /redirects/release-channels.md: -------------------------------------------------------------------------------- 1 | % Release Channels 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > The Rust project uses a concept called ‘release channels’ to manage releases. 6 | > New nightly releases are created once a day. 7 | > Every six weeks, the latest nightly release is promoted to ‘Beta’. 8 | > At that point, it will only receive patches to fix serious errors. 9 | > Six weeks later, the beta is promoted to ‘Stable’. 10 | 11 | --- 12 | 13 | This chapter does not exist yet in [the second edition][2]. 14 | You can check out other resources that describe release channels. 15 | 16 | * **[In the Rustup documentation: Keeping Rust Up-to-date][4]** 17 | * [On the website: Install Rust][5] 18 | * [In the Rust RFCs: RFC 507 — Release Channels][3] 19 | * [In the second edition: How Rust is Made and “Nightly Rust”][2] 20 | * [In the first edition: Ch 4.11 — Release Channels][1] 21 | 22 | 23 | [1]: first-edition/release-channels.html 24 | [2]: second-edition/appendix-07-nightly-rust.html 25 | [3]: https://github.com/rust-lang/rfcs/blob/master/text/0507-release-channels.md 26 | [4]: https://github.com/rust-lang-nursery/rustup.rs/blob/master/README.md#keeping-rust-up-to-date 27 | [5]: https://www.rust-lang.org/en-US/install.html 28 | 29 | -------------------------------------------------------------------------------- /redirects/strings.md: -------------------------------------------------------------------------------- 1 | % Strings 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > A `String` is allocated on the heap and as such is able to store an amount of text that is unknown to us at compile time. 6 | > You can create a `String` from a string literal using the `from` function. 7 | > A _string slice_ is a reference to part of a `String`. 8 | 9 | ```rust 10 | let s = String::from("hello world"); 11 | 12 | let hello = &s[0..5]; 13 | let world = &s[6..11]; 14 | ``` 15 | 16 | --- 17 | 18 | Here are the relevant sections in the new and old books: 19 | 20 | * **[In second edition: Ch 8.02 — Strings][2]** 21 | * [In second edition: Ch 4.01 — Ownership, section The String Type][3] 22 | * [In second edition: Ch 4.03 — Slices, section String Slices][4] 23 | * [In the first edition: Ch 3.17 — Strings][1] 24 | 25 | 26 | [1]: first-edition/strings.html 27 | [2]: second-edition/ch08-02-strings.html 28 | [3]: second-edition/ch04-01-what-is-ownership.html#the-string-type 29 | [4]: second-edition/ch04-03-slices.html#string-slices 30 | -------------------------------------------------------------------------------- /redirects/structs.md: -------------------------------------------------------------------------------- 1 | % Structs 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > A _struct_ is a custom data type that lets us name and package together multiple related values that make up a meaningful group. 6 | 7 | ```rust 8 | struct User { 9 | username: String, 10 | email: String, 11 | sign_in_count: u64, 12 | active: bool, 13 | } 14 | ``` 15 | 16 | --- 17 | 18 | Here are the relevant sections in the new and old books: 19 | 20 | * **[In second edition: Ch 5.00 — Structs][2]** 21 | * [In the first edition: Ch 3.12 — Structs][1] 22 | 23 | 24 | [1]: first-edition/structs.html 25 | [2]: second-edition/ch05-00-structs.html 26 | -------------------------------------------------------------------------------- /redirects/syntax-and-semantics.md: -------------------------------------------------------------------------------- 1 | % Syntax and Semantics 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | Here are the relevant sections in the new and old books: 6 | 7 | 8 | * **[In the second edition: Ch 3.00 — Common Programming Concepts][2]** 9 | * [In the second edition: Appendix A — Keywords][3] 10 | * [In the second edition: Appendix B — Operators][4] 11 | * [In the first edition: Ch 3 — Syntax and Semantics][1] 12 | 13 | 14 | [1]: first-edition/syntax-and-semantics.html 15 | [2]: second-edition/ch03-00-common-programming-concepts.html 16 | [3]: second-edition/appendix-01-keywords.html 17 | [4]: second-edition/appendix-02-operators.html 18 | 19 | -------------------------------------------------------------------------------- /redirects/syntax-index.md: -------------------------------------------------------------------------------- 1 | % Syntax Index 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | Here are the relevant sections in the new and old books: 6 | 7 | * **[In the second edition: Appendix A — Keywords][2]** 8 | * **[In the second edition: Appendix B — Operators][3]** 9 | * [In the first edition: Ch 6 — Syntax Index][1] 10 | 11 | 12 | [1]: first-edition/syntax-index.html 13 | [2]: second-edition/appendix-01-keywords.html 14 | [3]: second-edition/appendix-02-operators.html 15 | -------------------------------------------------------------------------------- /redirects/testing.md: -------------------------------------------------------------------------------- 1 | % Testing 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > Rust includes support for writing software tests within the language itself. 6 | 7 | ```rust 8 | #[cfg(test)] 9 | mod tests { 10 | #[test] 11 | fn it_works() { 12 | } 13 | } 14 | ``` 15 | 16 | --- 17 | 18 | Here are the relevant sections in the new and old books: 19 | 20 | * **[In the second edition: Ch 11.00 — Testing][2]** 21 | * [In the first edition: Ch 4.2 — Testing][1] 22 | 23 | 24 | [1]: first-edition/testing.html 25 | [2]: second-edition/ch11-00-testing.html 26 | -------------------------------------------------------------------------------- /redirects/the-stack-and-the-heap.md: -------------------------------------------------------------------------------- 1 | % The Stack and the Heap 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > Both the stack and the heap are parts of memory that is available to your code to use at runtime, but they are structured in different ways. 6 | > The stack stores values in the order it gets them and removes the values in the opposite order. 7 | > All data on the stack must take up a known, fixed size. 8 | > For data with a size unknown to us at compile time or a size that might change, we can store data on the heap instead. 9 | 10 | --- 11 | 12 | Here are the relevant sections in the new and old books: 13 | 14 | * **[In the second edition: Ch 4.01 — What is Ownership, section The Stack and the Heap][2]** 15 | * [In the first edition: Ch 4.1 — The Stack and the Heap][1] 16 | 17 | 18 | [1]: first-edition/the-stack-and-the-heap.html 19 | [2]: second-edition/ch04-01-what-is-ownership.html#the-stack-and-the-heap 20 | -------------------------------------------------------------------------------- /redirects/trait-objects.md: -------------------------------------------------------------------------------- 1 | % Trait Objects 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > Trait objects combine the data made up of the pointer to a concrete object with the behavior of the methods defined in the trait. 6 | > A trait defines behavior that we need in a given situation. 7 | > We can then use a trait as a trait object in places where we would use a concrete type or a generic type. 8 | 9 | ```rust,ignore 10 | pub struct InputBox { 11 | pub label: String, 12 | } 13 | 14 | impl Draw for InputBox { 15 | fn draw(&self) { 16 | // Code to actually draw an input box 17 | } 18 | } 19 | 20 | pub struct Button { 21 | pub label: String, 22 | } 23 | 24 | impl Draw for Button { 25 | fn draw(&self) { 26 | // Code to actually draw a button 27 | } 28 | } 29 | 30 | pub struct Screen { 31 | pub components: Vec, 32 | } 33 | 34 | impl Screen 35 | where T: Draw { 36 | pub fn run(&self) { 37 | for component in self.components.iter() { 38 | component.draw(); 39 | } 40 | } 41 | } 42 | 43 | fn main() { 44 | let screen = Screen { 45 | components: vec![ 46 | Box::new(InputBox { 47 | label: String::from("OK"), 48 | }), 49 | Box::new(Button { 50 | label: String::from("OK"), 51 | }), 52 | ], 53 | }; 54 | 55 | screen.run(); 56 | } 57 | ``` 58 | 59 | --- 60 | 61 | Here are the relevant sections in the new and old books: 62 | 63 | * **[In the second edition: Ch 17.02 — Trait Objects][2]** 64 | * [In the first edition: Ch 3.22 — Trait Objects][1] 65 | 66 | 67 | [1]: first-edition/trait-objects.html 68 | [2]: second-edition/ch17-02-trait-objects.html 69 | -------------------------------------------------------------------------------- /redirects/traits.md: -------------------------------------------------------------------------------- 1 | % Traits 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > Traits abstract over behavior that types can have in common. 6 | 7 | ```rust 8 | pub trait Summarizable { 9 | fn summary(&self) -> String; 10 | } 11 | ``` 12 | 13 | --- 14 | 15 | Here are the relevant sections in the new and old books: 16 | 17 | * **[In the second edition: Ch 10.02 — Traits][2]** 18 | * [In the second edition: Ch 19.03 — Advanced Traits][3] 19 | * [In the first edition: Ch 3.19 — Traits][1] 20 | 21 | 22 | [1]: first-edition/traits.html 23 | [2]: second-edition/ch10-02-traits.html 24 | [3]: second-edition/ch19-03-advanced-traits.html 25 | -------------------------------------------------------------------------------- /redirects/type-aliases.md: -------------------------------------------------------------------------------- 1 | % `type` aliases 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > Rust provides the ability to declare a _type alias_ with the `type` keyword to give an existing type another name. 6 | 7 | ```rust 8 | type Kilometers = i32; 9 | ``` 10 | 11 | --- 12 | 13 | Here are the relevant sections in the new and old books: 14 | 15 | * **[In the second edition: Ch 19.04 — Advanced Types, section Type Synonyms][2]** 16 | * [In the first edition: Ch 3.28 — `type` aliases][1] 17 | 18 | 19 | [1]: first-edition/type-aliases.html 20 | [2]: second-edition/ch19-04-advanced-types.html#type-aliases-create-type-synonyms 21 | 22 | -------------------------------------------------------------------------------- /redirects/ufcs.md: -------------------------------------------------------------------------------- 1 | % Universal Function Call Syntax 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > Rust cannot prevent a trait from having a method with the same name as another trait’s method, nor can it prevent us from implementing both of these traits on one type. 6 | > In order to be able to call each of the methods with the same name, then, we need to tell Rust which one we want to use. 7 | 8 | ```rust 9 | trait Pilot { 10 | fn fly(&self); 11 | } 12 | 13 | trait Wizard { 14 | fn fly(&self); 15 | } 16 | 17 | struct Human; 18 | 19 | impl Pilot for Human { 20 | # fn fly(&self) { 21 | # println!("This is your captain speaking."); 22 | # } 23 | } 24 | 25 | impl Wizard for Human { 26 | # fn fly(&self) { 27 | # println!("Up!"); 28 | # } 29 | } 30 | 31 | impl Human { 32 | # fn fly(&self) { 33 | # println!("*waving arms furiously*"); 34 | # } 35 | } 36 | 37 | fn main() { 38 | let person = Human; 39 | Pilot::fly(&person); 40 | Wizard::fly(&person); 41 | person.fly(); 42 | } 43 | ``` 44 | 45 | --- 46 | 47 | Here are the relevant sections in the new and old books: 48 | 49 | * **[In the second edition: Ch 19.03 — Advanced Traits, section Fully Qualified Syntax][2]** 50 | * [In the first edition: Ch 3.24 — Universal Function Call Syntax][1] 51 | 52 | 53 | [1]: first-edition/ufcs.html 54 | [2]: second-edition/ch19-03-advanced-traits.html#fully-qualified-syntax-for-disambiguation-calling-methods-with-the-same-name 55 | -------------------------------------------------------------------------------- /redirects/unsafe.md: -------------------------------------------------------------------------------- 1 | % `unsafe` 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > Rust has a second language hiding out inside of it, unsafe Rust, which does not enforce memory safety guarantees. 6 | 7 | --- 8 | 9 | Here are the relevant sections in the new and old books: 10 | 11 | * **[In the second edition: Ch 19.01 — Unsafe Rust][2]** 12 | * [The Rustonomicon, The Dark Arts of Advanced and Unsafe Rust Programming][3] 13 | * [In the first edition: Ch 3.36 — `unsafe`][1] 14 | 15 | 16 | [1]: first-edition/unsafe.html 17 | [2]: second-edition/ch19-01-unsafe-rust.html 18 | [3]: ../nomicon/index.html 19 | -------------------------------------------------------------------------------- /redirects/unsized-types.md: -------------------------------------------------------------------------------- 1 | % Unsized Types 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > Sometimes referred to as ‘DSTs’ or ‘unsized types’, these types let us talk about types whose size we can only know at runtime. 6 | > The `Sized` trait is automatically implemented for everything the compiler knows the size of at compile time. 7 | > A trait bound on `?Sized` is the opposite of a trait bound on `Sized`; that is, we would read this as “`T` may or may not be `Sized`”. 8 | 9 | ```rust,ignore 10 | fn generic(t: &T) { 11 | // ...snip... 12 | } 13 | ``` 14 | 15 | --- 16 | 17 | Here are the relevant sections in the new and old books: 18 | 19 | * **[In the second edition: Ch 19.04 — Advanced Types, section Dynamically Sized Types][2]** 20 | * [In the first edition: Ch 3.31 — Unsized Types][1] 21 | 22 | 23 | [1]: first-edition/unsized-types.html 24 | [2]: second-edition/ch19-04-advanced-types.html#dynamically-sized-types-and-sized 25 | -------------------------------------------------------------------------------- /redirects/using-rust-without-the-standard-library.md: -------------------------------------------------------------------------------- 1 | % Using Rust without the Standard Library 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > Rust’s standard library provides a lot of useful functionality, but assumes support for various features of its host system: threads, networking, heap allocation, and others. 6 | > There are systems that do not have these features, however. 7 | 8 | --- 9 | 10 | This particular chapter has moved to [the Unstable Book][2]. 11 | 12 | * **[In the Unstable Rust Book: `lang_items` — Writing an executable without stdlib][2]** 13 | * [In the first edition: Ch 4.12 — Using Rust without the Standard Library][1] 14 | 15 | 16 | [1]: first-edition/using-rust-without-the-standard-library.html 17 | [2]: ../unstable-book/language-features/lang-items.html#writing-an-executable-without-stdlib 18 | -------------------------------------------------------------------------------- /redirects/variable-bindings.md: -------------------------------------------------------------------------------- 1 | % Variable Bindings 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > Variable bindings bind some value to a name, so it can be used later. 6 | 7 | ```rust 8 | let foo = 5; 9 | ``` 10 | 11 | --- 12 | 13 | Here are the relevant sections in the new and old books: 14 | 15 | * **[In the second edition: Ch 2.00 — Guessing Game Tutorial, section Variables][2]** 16 | * [In the first edition: Ch 3.1 — Variable Bindings][1] 17 | 18 | 19 | [1]: first-edition/variable-bindings.html 20 | [2]: second-edition/ch02-00-guessing-game-tutorial.html#storing-values-with-variables 21 | -------------------------------------------------------------------------------- /redirects/vectors.md: -------------------------------------------------------------------------------- 1 | % Vectors 2 | 3 | There is a new edition of the book and this is an old link. 4 | 5 | > Vectors store more than one value in a single data structure that puts all the values next to each other in memory. 6 | > Vectors can only store values of the same type. 7 | 8 | ```rust 9 | let v: Vec = Vec::new(); 10 | let numbers = vec![1, 2, 3]; 11 | ``` 12 | 13 | --- 14 | 15 | Here are the relevant sections in the new and old books: 16 | 17 | * **[In the second edition: Ch 8.01 — Vectors][2]** 18 | * [In the first edition: Ch 3.7 — Vectors][1] 19 | 20 | 21 | [1]: first-edition/vectors.html 22 | [2]: second-edition/ch08-01-vectors.html 23 | 24 | -------------------------------------------------------------------------------- /second-edition/en/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rust-book" 3 | version = "0.0.1" 4 | authors = ["Steve Klabnik "] 5 | description = "The Rust Book" 6 | 7 | [[bin]] 8 | name = "concat_chapters" 9 | path = "tools/src/bin/concat_chapters.rs" 10 | 11 | [[bin]] 12 | name = "lfp" 13 | path = "tools/src/bin/lfp.rs" 14 | 15 | [[bin]] 16 | name = "link2print" 17 | path = "tools/src/bin/link2print.rs" 18 | 19 | [[bin]] 20 | name = "remove_links" 21 | path = "tools/src/bin/remove_links.rs" 22 | 23 | [[bin]] 24 | name = "remove_markup" 25 | path = "tools/src/bin/remove_markup.rs" 26 | 27 | [[bin]] 28 | name = "convert_quotes" 29 | path = "tools/src/bin/convert_quotes.rs" 30 | 31 | [dependencies] 32 | walkdir = "0.1.5" 33 | docopt = "0.6.82" 34 | rustc-serialize = "0.3.19" 35 | regex = "0.1.73" 36 | lazy_static = "0.2.1" 37 | -------------------------------------------------------------------------------- /second-edition/en/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010-2017 The Rust Project Developers 2 | 3 | Permission is hereby granted, free of charge, to any 4 | person obtaining a copy of this software and associated 5 | documentation files (the "Software"), to deal in the 6 | Software without restriction, including without 7 | limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software 10 | is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice 14 | shall be included in all copies or substantial portions 15 | of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 18 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 19 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 24 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. 26 | -------------------------------------------------------------------------------- /second-edition/en/book.toml: -------------------------------------------------------------------------------- 1 | [book] 2 | title = "The Rust Programming Language" 3 | author = "Steve Klabnik and Carol Nichols, with Contributions from the Rust Community" 4 | -------------------------------------------------------------------------------- /second-edition/en/convert-quotes.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2017 The Rust Project Developers. See the COPYRIGHT 3 | # file at the top-level directory of this distribution and at 4 | # http://rust-lang.org/COPYRIGHT. 5 | # 6 | # Licensed under the Apache License, Version 2.0 or the MIT license 8 | # , at your 9 | # option. This file may not be copied, modified, or distributed 10 | # except according to those terms. 11 | 12 | set -eu 13 | 14 | dir=$1 15 | 16 | mkdir -p "tmp/$dir" 17 | 18 | for f in $dir/*.md 19 | do 20 | cat "$f" | cargo run --bin convert_quotes > "tmp/$f" 21 | mv "tmp/$f" "$f" 22 | done 23 | -------------------------------------------------------------------------------- /second-edition/en/doc-to-md.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2016 The Rust Project Developers. See the COPYRIGHT 3 | # file at the top-level directory of this distribution and at 4 | # http://rust-lang.org/COPYRIGHT. 5 | # 6 | # Licensed under the Apache License, Version 2.0 or the MIT license 8 | # , at your 9 | # option. This file may not be copied, modified, or distributed 10 | # except according to those terms. 11 | 12 | set -eu 13 | 14 | # Get all the docx files in the tmp dir, 15 | ls tmp/*.docx | \ 16 | # Extract just the filename so we can reuse it easily. 17 | xargs -n 1 basename -s .docx | \ 18 | while IFS= read -r filename; do 19 | # Make a directory to put the XML in 20 | mkdir -p "tmp/$filename" 21 | # Unzip the docx to get at the xml 22 | unzip -o "tmp/$filename.docx" -d "tmp/$filename" 23 | # Convert to markdown with XSL 24 | xsltproc tools/docx-to-md.xsl "tmp/$filename/word/document.xml" | \ 25 | # Hard wrap at 80 chars at word bourdaries 26 | fold -w 80 -s | \ 27 | # Remove trailing whitespace & save in the nostarch dir for comparison 28 | sed -e "s/ *$//" > "nostarch/$filename.md" 29 | done 30 | -------------------------------------------------------------------------------- /second-edition/en/dot/trpl04-01.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | rankdir=LR; 3 | overlap=false; 4 | dpi=300.0; 5 | node [shape="plaintext"]; 6 | 7 | table0[label=< 8 | 9 | 10 | 11 | 12 | 13 |
s1
namevalue
ptr
len5
capacity5
>]; 14 | table1[label=< 15 | 16 | 17 | 18 | 19 | 20 | 21 |
indexvalue
0h
1e
2l
3l
4o
>]; 22 | 23 | edge[tailclip="false"]; 24 | table0:pointer:c -> table1:pointee; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /second-edition/en/dot/trpl04-02.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | rankdir=LR; 3 | overlap=false; 4 | dpi=300.0; 5 | node [shape="plaintext"]; 6 | 7 | table0[label=< 8 | 9 | 10 | 11 | 12 | 13 |
s1
namevalue
ptr
len5
capacity5
>]; 14 | table3[label=< 15 | 16 | 17 | 18 | 19 | 20 |
s2
namevalue
ptr
len5
capacity5
>]; 21 | 22 | table1[label=< 23 | 24 | 25 | 26 | 27 | 28 | 29 |
indexvalue
0h
1e
2l
3l
4o
>]; 30 | 31 | edge[tailclip="false"]; 32 | table0:pointer:c -> table1:pointee; 33 | table3:pointer:c -> table1:pointee; 34 | } 35 | 36 | -------------------------------------------------------------------------------- /second-edition/en/dot/trpl04-03.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | rankdir=LR; 3 | overlap=false; 4 | dpi=300.0; 5 | node [shape="plaintext"]; 6 | 7 | table0[label=< 8 | 9 | 10 | 11 | 12 | 13 |
s2
namevalue
ptr
len5
capacity5
>]; 14 | table1[label=< 15 | 16 | 17 | 18 | 19 | 20 | 21 |
indexvalue
0h
1e
2l
3l
4o
>]; 22 | 23 | table3[label=< 24 | 25 | 26 | 27 | 28 | 29 |
s1
namevalue
ptr
len5
capacity5
>]; 30 | table4[label=< 31 | 32 | 33 | 34 | 35 | 36 | 37 |
indexvalue
0h
1e
2l
3l
4o
>]; 38 | 39 | 40 | edge[tailclip="false"]; 41 | table0:pointer:c -> table1:pointee; 42 | table3:pointer:c -> table4:pointee; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /second-edition/en/dot/trpl04-04.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | rankdir=LR; 3 | overlap=false; 4 | dpi=300.0; 5 | node [shape="plaintext"]; 6 | 7 | table0[label=< 8 | 9 | 10 | 11 | 12 | 13 |
s1
namevalue
ptr
len5
capacity5
>]; 14 | table3[label=< 15 | 16 | 17 | 18 | 19 | 20 |
s2
namevalue
ptr
len5
capacity5
>]; 21 | 22 | table1[label=< 23 | 24 | 25 | 26 | 27 | 28 | 29 |
indexvalue
0h
1e
2l
3l
4o
>]; 30 | 31 | edge[tailclip="false"]; 32 | table0:pointer:c -> table1:pointee; 33 | table3:pointer:c -> table1:pointee; 34 | } 35 | 36 | -------------------------------------------------------------------------------- /second-edition/en/dot/trpl04-05.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | rankdir=LR; 3 | overlap=false; 4 | dpi=300.0; 5 | node [shape="plaintext"]; 6 | 7 | table0[label=< 8 | 9 | 10 | 11 |
s
namevalue
ptr
>]; 12 | table1[label=< 13 | 14 | 15 | 16 | 17 | 18 |
s1
namevalue
ptr
len5
capacity5
>]; 19 | table2[label=< 20 | 21 | 22 | 23 | 24 | 25 | 26 |
indexvalue
0h
1e
2l
3l
4o
>]; 27 | 28 | edge[tailclip="false"]; 29 | table1:pointer:c -> table2:pointee; 30 | table0:borrower:c -> table1:borrowee; 31 | } 32 | 33 | -------------------------------------------------------------------------------- /second-edition/en/dot/trpl04-06.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | rankdir=LR; 3 | overlap=false; 4 | dpi=300.0; 5 | node [shape="plaintext"]; 6 | 7 | table0[label=< 8 | 9 | 10 | 11 | 12 |
world
namevalue
ptr
len5
>]; 13 | 14 | table3[label=< 15 | 16 | 17 | 18 | 19 | 20 |
s
namevalue
ptr
len11
capacity11
>]; 21 | table4[label=< 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 |
indexvalue
0h
1e
2l
3l
4o
5
6w
7o
8r
9l
10d
>]; 35 | 36 | 37 | edge[tailclip="false"]; 38 | table0:pointer2:c -> table4:pointee2; 39 | table3:pointer:c -> table4:pointee; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /second-edition/en/dot/trpl15-01.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | rankdir=LR; 3 | overlap=false; 4 | dpi=300.0; 5 | node [shape="plaintext"]; 6 | 7 | table0[label=< 8 | 9 | 22 |
Cons
i32 10 | 11 | 21 |
Cons
i32 12 | 13 | 20 |
Cons
i32 14 | 15 | 19 |
Cons
i32 16 | 17 | 18 |
Cons
i32
>]; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /second-edition/en/dot/trpl15-02.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | rankdir=LR; 3 | overlap=false; 4 | dpi=300.0; 5 | node [shape="plaintext"]; 6 | 7 | table0[label=< 8 | 9 | 10 | 16 |
Cons
i32 11 | 12 | 13 | 14 |
Box
usize
15 |
>]; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /second-edition/en/dot/trpl15-03.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | rankdir=LR; 3 | overlap=false; 4 | dpi=300.0; 5 | node [shape="plaintext"]; 6 | 7 | table4[label=< 8 | 9 |
b
>]; 10 | 11 | table5[label=< 12 | 13 |
3
>]; 14 | 15 | 16 | table0[label=< 17 | 18 |
a
>]; 19 | 20 | table1[label=< 21 | 22 |
5
>]; 23 | 24 | table2[label=< 25 | 26 |
10
>]; 27 | 28 | table3[label=< 29 | 30 |
Nil
>]; 31 | 32 | 33 | table6[label=< 34 | 35 |
c
>]; 36 | 37 | table7[label=< 38 | 39 |
4
>]; 40 | 41 | 42 | edge[tailclip="false"]; 43 | table0:ptr0:c -> table1:pte0; 44 | table1:ptr1:c -> table2:pte1; 45 | table2:ptr2:c -> table3:pte2; 46 | table4:ptr4:c -> table5:pte4; 47 | table5:ptr5:c -> table1:pte0; 48 | table6:ptr6:c -> table7:pte6; 49 | table7:ptr7:c -> table1:pte0; 50 | } 51 | 52 | -------------------------------------------------------------------------------- /second-edition/en/nostarch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2016 The Rust Project Developers. See the COPYRIGHT 3 | # file at the top-level directory of this distribution and at 4 | # http://rust-lang.org/COPYRIGHT. 5 | # 6 | # Licensed under the Apache License, Version 2.0 or the MIT license 8 | # , at your 9 | # option. This file may not be copied, modified, or distributed 10 | # except according to those terms. 11 | 12 | set -eu 13 | 14 | cargo build --release 15 | 16 | mkdir -p tmp 17 | rm -rf tmp/*.md 18 | 19 | # Get all the markdown files in the src dir, 20 | ls src/${1:-""}*.md | \ 21 | # except for SUMMARY.md. 22 | grep -v SUMMARY.md | \ 23 | # Extract just the filename so we can reuse it easily. 24 | xargs -n 1 basename | \ 25 | # Remove all links followed by , then 26 | # Change all remaining links from markdown to italicized inline text. 27 | while IFS= read -r filename; do 28 | < "src/$filename" ./target/release/remove_links \ 29 | | ./target/release/link2print \ 30 | | ./target/release/remove_markup > "tmp/$filename" 31 | done 32 | # Concat the files into the nostarch dir. 33 | ./target/release/concat_chapters tmp nostarch 34 | -------------------------------------------------------------------------------- /second-edition/en/nostarch/odt/appendix.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/en/nostarch/odt/appendix.docx -------------------------------------------------------------------------------- /second-edition/en/nostarch/odt/chapter00.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/en/nostarch/odt/chapter00.docx -------------------------------------------------------------------------------- /second-edition/en/nostarch/odt/chapter01.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/en/nostarch/odt/chapter01.docx -------------------------------------------------------------------------------- /second-edition/en/nostarch/odt/chapter02.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/en/nostarch/odt/chapter02.doc -------------------------------------------------------------------------------- /second-edition/en/nostarch/odt/chapter03.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/en/nostarch/odt/chapter03.docx -------------------------------------------------------------------------------- /second-edition/en/nostarch/odt/chapter04.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/en/nostarch/odt/chapter04.docx -------------------------------------------------------------------------------- /second-edition/en/nostarch/odt/chapter05.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/en/nostarch/odt/chapter05.docx -------------------------------------------------------------------------------- /second-edition/en/nostarch/odt/chapter06.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/en/nostarch/odt/chapter06.docx -------------------------------------------------------------------------------- /second-edition/en/nostarch/odt/chapter07.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/en/nostarch/odt/chapter07.docx -------------------------------------------------------------------------------- /second-edition/en/nostarch/odt/chapter08.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/en/nostarch/odt/chapter08.docx -------------------------------------------------------------------------------- /second-edition/en/nostarch/odt/chapter09.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/en/nostarch/odt/chapter09.docx -------------------------------------------------------------------------------- /second-edition/en/nostarch/odt/chapter10.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/en/nostarch/odt/chapter10.docx -------------------------------------------------------------------------------- /second-edition/en/nostarch/odt/chapter11.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/en/nostarch/odt/chapter11.docx -------------------------------------------------------------------------------- /second-edition/en/nostarch/odt/chapter12.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/en/nostarch/odt/chapter12.docx -------------------------------------------------------------------------------- /second-edition/en/nostarch/odt/chapter13.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/en/nostarch/odt/chapter13.docx -------------------------------------------------------------------------------- /second-edition/en/nostarch/odt/chapter14.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/en/nostarch/odt/chapter14.docx -------------------------------------------------------------------------------- /second-edition/en/nostarch/odt/chapter15.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/en/nostarch/odt/chapter15.docx -------------------------------------------------------------------------------- /second-edition/en/nostarch/odt/chapter16.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/en/nostarch/odt/chapter16.docx -------------------------------------------------------------------------------- /second-edition/en/nostarch/odt/chapter17.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/en/nostarch/odt/chapter17.docx -------------------------------------------------------------------------------- /second-edition/en/nostarch/odt/chapter18.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/en/nostarch/odt/chapter18.docx -------------------------------------------------------------------------------- /second-edition/en/nostarch/odt/chapter19.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/en/nostarch/odt/chapter19.docx -------------------------------------------------------------------------------- /second-edition/en/nostarch/odt/chapter20.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/en/nostarch/odt/chapter20.docx -------------------------------------------------------------------------------- /second-edition/en/nostarch/odt/index.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/en/nostarch/odt/index.docx -------------------------------------------------------------------------------- /second-edition/en/src/appendix-00.md: -------------------------------------------------------------------------------- 1 | # Appendix 2 | 3 | The following sections contain reference material you may find useful in your 4 | Rust journey. 5 | -------------------------------------------------------------------------------- /second-edition/en/src/appendix-05-translation.md: -------------------------------------------------------------------------------- 1 | ## Appendix E: Translations of the Book 2 | 3 | For resources in languages other than English. Most are still in progress; see 4 | [the Translations label][label] to help or let us know about a new translation! 5 | 6 | [label]: https://github.com/rust-lang/book/issues?q=is%3Aopen+is%3Aissue+label%3ATranslations 7 | 8 | - [Português](https://github.com/rust-br/rust-book-pt-br) (BR) 9 | - [Português](https://github.com/nunojesus/rust-book-pt-pt) (PT) 10 | - [Tiếng việt](https://github.com/hngnaig/rust-lang-book/tree/vi-VN) 11 | - [简体中文](http://www.broadview.com.cn/article/144), [alternate](https://github.com/KaiserY/trpl-zh-cn) 12 | - [Українська](https://github.com/pavloslav/rust-book-uk-ua) 13 | - [Español](https://github.com/thecodix/book) 14 | - [Italiano](https://github.com/AgeOfWar/rust-book-it) 15 | - [Русский](https://github.com/iDeBugger/rust-book-ru) 16 | - [한국어](https://github.com/rinthel/rust-lang-book-ko) 17 | - [日本語](https://github.com/hazama-yuinyan/book) 18 | - [Français](https://github.com/quadrifoglio/rust-book-fr) 19 | - [Polski](https://github.com/paytchoo/book-pl) 20 | - [עברית](https://github.com/idanmel/rust-book-heb) 21 | - [Cebuano](https://github.com/agentzero1/book) 22 | - [Tagalog](https://github.com/josephace135/book) 23 | -------------------------------------------------------------------------------- /second-edition/en/src/ch01-00-getting-started.md: -------------------------------------------------------------------------------- 1 | # Getting Started 2 | 3 | Let’s start your Rust journey! There's a lot to learn, but every journey starts 4 | somewhere. In this chapter, we’ll discuss: 5 | 6 | * Installing Rust on Linux, macOS, and Windows 7 | * Writing a program that prints `Hello, world!` 8 | * Using `cargo`, Rust’s package manager and build system 9 | -------------------------------------------------------------------------------- /second-edition/en/src/ch03-00-common-programming-concepts.md: -------------------------------------------------------------------------------- 1 | # Common Programming Concepts 2 | 3 | This chapter covers concepts that appear in almost every programming language 4 | and how they work in Rust. Many programming languages have much in common at 5 | their core. None of the concepts presented in this chapter are unique to Rust, 6 | but we’ll discuss them in the context of Rust and explain the conventions 7 | around using these concepts. 8 | 9 | Specifically, you’ll learn about variables, basic types, functions, comments, 10 | and control flow. These foundations will be in every Rust program, and learning 11 | them early will give you a strong core to start from. 12 | 13 | > ### Keywords 14 | > 15 | > The Rust language has a set of *keywords* that are reserved for use by 16 | > the language only, much as in other languages. Keep in mind that you cannot 17 | > use these words as names of variables or functions. Most of the keywords have 18 | > special meanings, and you’ll be using them to do various tasks in your Rust 19 | > programs; a few have no current functionality associated with them but have 20 | > been reserved for functionality that might be added to Rust in the future. You 21 | > can find a list of the keywords in Appendix A. 22 | -------------------------------------------------------------------------------- /second-edition/en/src/ch03-04-comments.md: -------------------------------------------------------------------------------- 1 | ## Comments 2 | 3 | All programmers strive to make their code easy to understand, but sometimes 4 | extra explanation is warranted. In these cases, programmers leave notes, or 5 | *comments*, in their source code that the compiler will ignore but people 6 | reading the source code may find useful. 7 | 8 | Here’s a simple comment: 9 | 10 | ```rust 11 | // hello, world 12 | ``` 13 | 14 | In Rust, comments must start with two slashes and continue until the end of the 15 | line. For comments that extend beyond a single line, you’ll need to include 16 | `//` on each line, like this: 17 | 18 | ```rust 19 | // So we’re doing something complicated here, long enough that we need 20 | // multiple lines of comments to do it! Whew! Hopefully, this comment will 21 | // explain what’s going on. 22 | ``` 23 | 24 | Comments can also be placed at the end of lines containing code: 25 | 26 | Filename: src/main.rs 27 | 28 | ```rust 29 | fn main() { 30 | let lucky_number = 7; // I’m feeling lucky today 31 | } 32 | ``` 33 | 34 | But you’ll more often see them used in this format, with the comment on a 35 | separate line above the code it’s annotating: 36 | 37 | Filename: src/main.rs 38 | 39 | ```rust 40 | fn main() { 41 | // I’m feeling lucky today 42 | let lucky_number = 7; 43 | } 44 | ``` 45 | 46 | Rust also has another kind of comment, documentation comments, which we’ll 47 | discuss in Chapter 14. 48 | -------------------------------------------------------------------------------- /second-edition/en/src/ch04-00-understanding-ownership.md: -------------------------------------------------------------------------------- 1 | # Understanding Ownership 2 | 3 | Ownership is Rust’s most unique feature, and it enables Rust to make memory 4 | safety guarantees without needing a garbage collector. Therefore, it’s 5 | important to understand how ownership works in Rust. In this chapter, we’ll 6 | talk about ownership as well as several related features: borrowing, slices, 7 | and how Rust lays data out in memory. 8 | -------------------------------------------------------------------------------- /second-edition/en/src/ch05-00-structs.md: -------------------------------------------------------------------------------- 1 | # Using Structs to Structure Related Data 2 | 3 | A *struct*, or *structure*, is a custom data type that lets you name and 4 | package together multiple related values that make up a meaningful group. If 5 | you’re familiar with an object-oriented language, a *struct* is like an 6 | object’s data attributes. In this chapter, we’ll compare and contrast tuples 7 | with structs, demonstrate how to use structs, and discuss how to define methods 8 | and associated functions to specify behavior associated with a struct’s data. 9 | Structs and enums (discussed in Chapter 6) are the building blocks for creating 10 | new types in your program’s domain to take full advantage of Rust’s compile 11 | time type checking. 12 | -------------------------------------------------------------------------------- /second-edition/en/src/ch06-00-enums.md: -------------------------------------------------------------------------------- 1 | # Enums and Pattern Matching 2 | 3 | In this chapter we’ll look at *enumerations*, also referred to as *enums*. 4 | Enums allow you to define a type by enumerating its possible values. First, 5 | we’ll define and use an enum to show how an enum can encode meaning along with 6 | data. Next, we’ll explore a particularly useful enum, called `Option`, which 7 | expresses that a value can be either something or nothing. Then we’ll look at 8 | how pattern matching in the `match` expression makes it easy to run different 9 | code for different values of an enum. Finally, we’ll cover how the `if let` 10 | construct is another convenient and concise idiom available to you to handle 11 | enums in your code. 12 | 13 | Enums are a feature in many languages, but their capabilities differ in each 14 | language. Rust’s enums are most similar to *algebraic data types* in functional 15 | languages, such as F#, OCaml, and Haskell. 16 | -------------------------------------------------------------------------------- /second-edition/en/src/ch07-00-modules.md: -------------------------------------------------------------------------------- 1 | # Using Modules to Reuse and Organize Code 2 | 3 | When you start writing programs in Rust, your code might live solely in the 4 | `main` function. As your code grows, you’ll eventually move functionality into 5 | other functions for reuse and better organization. By splitting your code into 6 | smaller chunks, you make each chunk easier to understand on its own. But what 7 | happens if you have too many functions? Rust has a module system that enables 8 | the reuse of code in an organized fashion. 9 | 10 | In the same way that you extract lines of code into a function, you can extract 11 | functions (and other code, like structs and enums) into different modules. A 12 | *module* is a namespace that contains definitions of functions or types, and 13 | you can choose whether those definitions are visible outside their module 14 | (public) or not (private). Here’s an overview of how modules work: 15 | 16 | * The `mod` keyword declares a new module. Code within the module appears 17 | either immediately following this declaration within curly brackets or in 18 | another file. 19 | * By default, functions, types, constants, and modules are private. The `pub` 20 | keyword makes an item public and therefore visible outside its namespace. 21 | * The `use` keyword brings modules, or the definitions inside modules, into 22 | scope so it’s easier to refer to them. 23 | 24 | We’ll look at each of these parts to see how they fit into the whole. 25 | -------------------------------------------------------------------------------- /second-edition/en/src/ch08-00-common-collections.md: -------------------------------------------------------------------------------- 1 | # Common Collections 2 | 3 | Rust’s standard library includes a number of very useful data structures called 4 | *collections*. Most other data types represent one specific value, but 5 | collections can contain multiple values. Unlike the built-in array and tuple 6 | types, the data these collections point to is stored on the heap, which means 7 | the amount of data does not need to be known at compile time and can grow or 8 | shrink as the program runs. Each kind of collection has different capabilities 9 | and costs, and choosing an appropriate one for your current situation is a 10 | skill you’ll develop over time. In this chapter, we’ll discuss three 11 | collections that are used very often in Rust programs: 12 | 13 | * A *vector* allows you to store a variable number of values next to each other. 14 | * A *string* is a collection of characters. We’ve mentioned the `String` type 15 | previously, but in this chapter we’ll talk about it in depth. 16 | * A *hash map* allows you to associate a value with a particular key. It’s a 17 | particular implementation of the more general data structure called a *map*. 18 | 19 | To learn about the other kinds of collections provided by the standard library, 20 | see [the documentation][collections]. 21 | 22 | [collections]: ../../std/collections/index.html 23 | 24 | We’ll discuss how to create and update vectors, strings, and hash maps, as well 25 | as what makes each special. 26 | -------------------------------------------------------------------------------- /second-edition/en/src/ch09-00-error-handling.md: -------------------------------------------------------------------------------- 1 | # Error Handling 2 | 3 | Rust’s commitment to reliability extends to error handling. Errors are a fact 4 | of life in software, so Rust has a number of features for handling situations 5 | in which something goes wrong. In many cases, Rust requires you to acknowledge 6 | the possibility of an error and take some action before your code will compile. 7 | This requirement makes your program more robust by ensuring that you’ll 8 | discover errors and handle them appropriately before you’ve deployed your code 9 | to production! 10 | 11 | Rust groups errors into two major categories: *recoverable* and *unrecoverable* 12 | errors. For a recoverable error, such as a file not found error, it’s 13 | reasonable to report the problem to the user and retry the operation. 14 | Unrecoverable errors are always symptoms of bugs, like trying to access a 15 | location beyond the end of an array. 16 | 17 | Most languages don’t distinguish between these two kinds of errors and handle 18 | both in the same way, using mechanisms such as exceptions. Rust doesn’t have 19 | exceptions. Instead, it has the type `Result` for recoverable errors and 20 | the `panic!` macro that stops execution when the program encounters an 21 | unrecoverable error. This chapter covers calling `panic!` first and then talks 22 | about returning `Result` values. Additionally, we’ll explore 23 | considerations when deciding whether to try to recover from an error or to stop 24 | execution. 25 | -------------------------------------------------------------------------------- /second-edition/en/src/ch13-00-functional-features.md: -------------------------------------------------------------------------------- 1 | # Functional Language Features: Iterators and Closures 2 | 3 | Rust’s design has taken inspiration from many existing languages and 4 | techniques, and one significant influence is *functional programming*. 5 | Programming in a functional style often includes using functions as values by 6 | passing them in arguments, returning them from other functions, assigning them 7 | to variables for later execution, and so forth. 8 | 9 | In this chapter, we won’t debate the issue of what functional programming is or 10 | isn’t but will instead discuss some features of Rust that are similar to 11 | features in many languages often referred to as functional. 12 | 13 | More specifically, we’ll cover: 14 | 15 | * *Closures*, a function-like construct you can store in a variable 16 | * *Iterators*, a way of processing a series of elements 17 | * How to use these two features to improve the I/O project in Chapter 12 18 | * The performance of these two features (Spoiler alert: they’re faster than you 19 | might think!) 20 | 21 | Other Rust features, such as pattern matching and enums, which we’ve covered in 22 | other chapters, are influenced by the functional style as well. Mastering 23 | closures and iterators is an important part of writing idiomatic, fast Rust 24 | code, so we’ll devote this entire chapter to them. 25 | -------------------------------------------------------------------------------- /second-edition/en/src/ch14-00-more-about-cargo.md: -------------------------------------------------------------------------------- 1 | # More About Cargo and Crates.io 2 | 3 | So far we’ve used only the most basic features of Cargo to build, run, and test 4 | our code, but it can do a lot more. In this chapter, we’ll discuss some of its 5 | other, more advanced features to show you how to do the following: 6 | 7 | * Customize your build through release profiles 8 | * Publish libraries on [crates.io](https://crates.io) 9 | * Organize large projects with workspaces 10 | * Install binaries from [crates.io](https://crates.io) 11 | * Extend Cargo using custom commands 12 | 13 | Cargo can do even more than what we cover in this chapter, so for a full 14 | explanation of all its features, see [its 15 | documentation](https://doc.rust-lang.org/cargo/). 16 | -------------------------------------------------------------------------------- /second-edition/en/src/ch14-05-extending-cargo.md: -------------------------------------------------------------------------------- 1 | ## Extending Cargo with Custom Commands 2 | 3 | Cargo is designed so you can extend it with new subcommands without having to 4 | modify Cargo. If a binary in your `$PATH` is named `cargo-something`, you can 5 | run it as if it was a Cargo subcommand by running `cargo something`. Custom 6 | commands like this are also listed when you run `cargo --list`. Being able to 7 | use `cargo install` to install extensions and then run them just like the 8 | built-in Cargo tools is a super convenient benefit of Cargo’s design! 9 | 10 | ## Summary 11 | 12 | Sharing code with Cargo and [crates.io](https://crates.io) is 13 | part of what makes the Rust ecosystem useful for many different tasks. Rust’s 14 | standard library is small and stable, but crates are easy to share, use, and 15 | improve on a timeline different from that of the language. Don’t be shy about 16 | sharing code that’s useful to you on [crates.io](https://crates.io); it’s likely that it will be useful to someone else as well! 18 | -------------------------------------------------------------------------------- /second-edition/en/src/ch17-00-oop.md: -------------------------------------------------------------------------------- 1 | # Object Oriented Programming Features of Rust 2 | 3 | Object-oriented programming (OOP) is a way of modeling programs. Objects came 4 | from Simula in the 1960s. Those objects influenced Alan Kay’s programming 5 | architecture in which objects pass messages to each other. He coined the term 6 | *object-oriented programming* in 1967 to describe this architecture. Many 7 | competing definitions describe what OOP is; some definitions would classify 8 | Rust as object oriented, but other definitions would not. In this chapter, 9 | we’ll explore certain characteristics that are commonly considered object 10 | oriented and how those characteristics translate to idiomatic Rust. We’ll then 11 | show you how to implement an object-oriented design pattern in Rust and discuss 12 | the trade-offs of doing so versus implementing a solution using some of Rust’s 13 | strengths instead. 14 | -------------------------------------------------------------------------------- /second-edition/en/src/ch18-00-patterns.md: -------------------------------------------------------------------------------- 1 | # Patterns and Matching 2 | 3 | Patterns are a special syntax in Rust for matching against the structure of 4 | types, both complex and simple. Using patterns in conjunction with `match` 5 | expressions and other constructs gives you more control over a program’s 6 | control flow. A pattern consists of some combination of the following: 7 | 8 | * Literals 9 | * Destructured arrays, enums, structs, or tuples 10 | * Variables 11 | * Wildcards 12 | * Placeholders 13 | 14 | These components describe the shape of the data we’re working with, which we 15 | then match against values to determine whether our program has the correct data 16 | to continue running a particular piece of code. 17 | 18 | To use a pattern, we compare it to some value. If the pattern matches the 19 | value, we use the value parts in our code. Recall the `match` expressions in 20 | Chapter 6 that used patterns, such as the coin-sorting machine example. If the 21 | value fits the shape of the pattern, we can use the named pieces. If it 22 | doesn’t, the code associated with the pattern won’t run. 23 | 24 | This chapter is a reference on all things related to patterns. We’ll cover the 25 | valid places to use patterns, the difference between refutable and irrefutable 26 | patterns, and the different kinds of pattern syntax that you might see. By the 27 | end of the chapter, you’ll know how to use patterns to express many concepts in 28 | a clear way. 29 | -------------------------------------------------------------------------------- /second-edition/en/src/ch19-00-advanced-features.md: -------------------------------------------------------------------------------- 1 | # Advanced Features 2 | 3 | By now, you’ve learned the most commonly used parts of the Rust programming 4 | language. Before we do one more project in Chapter 20, we’ll look at a few 5 | aspects of the language you might run into every once in a while. You can use 6 | this chapter as a reference for when you encounter any unknowns when using 7 | Rust. The features you’ll learn to use in this chapter are useful in very 8 | specific situations. Although you might not reach for them often, we want to 9 | make sure you have a grasp of all the features Rust has to offer. 10 | 11 | In this chapter, we’ll cover: 12 | 13 | * Unsafe Rust: how to opt out of some of Rust’s guarantees and take 14 | responsibility for manually upholding those guarantees 15 | * Advanced lifetimes: syntax for complex lifetime situations 16 | * Advanced traits: associated types, default type parameters, fully qualified 17 | syntax, supertraits, and the newtype pattern in relation to traits 18 | * Advanced types: more about the newtype pattern, type aliases, the never type, 19 | and dynamically sized types 20 | * Advanced functions and closures: function pointers and returning closures 21 | 22 | It’s a panoply of Rust features with something for everyone! Let’s dive in! 23 | -------------------------------------------------------------------------------- /second-edition/en/src/ch20-00-final-project-a-web-server.md: -------------------------------------------------------------------------------- 1 | # Final Project: Building a Multithreaded Web Server 2 | 3 | It’s been a long journey, but we’ve reached the end of the book. In this 4 | chapter, we’ll build one more project together to demonstrate some of the 5 | concepts we covered in the final chapters, as well as recap some earlier 6 | lessons. 7 | 8 | For our final project, we’ll make a web server that says “hello” and looks like 9 | Figure 20-1 in a web browser. 10 | 11 | ![hello from rust](img/trpl20-01.png) 12 | 13 | Figure 20-1: Our final shared project 14 | 15 | Here is the plan to build the web server: 16 | 17 | 1. Learn a bit about TCP and HTTP. 18 | 2. Listen for TCP connections on a socket. 19 | 3. Parse a small number of HTTP requests. 20 | 4. Create a proper HTTP response. 21 | 5. Improve the throughput of our server with a thread pool. 22 | 23 | But before we get started, we should mention one detail: the method we’ll use 24 | won’t be the best way to build a web server with Rust. A number of 25 | production-ready crates are available on *https://crates.io/* that provide more 26 | complete web server and thread pool implementations than we’ll build. 27 | 28 | However, our intention in this chapter is to help you learn, not to take the 29 | easy route. Because Rust is a systems programming language, we can choose the 30 | level of abstraction we want to work with and can go to a lower level than is 31 | possible or practical in other languages. We’ll write the basic HTTP server and 32 | thread pool manually so you can learn the general ideas and techniques behind 33 | the crates you might use in the future. 34 | -------------------------------------------------------------------------------- /second-edition/en/src/img/trpl14-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/en/src/img/trpl14-01.png -------------------------------------------------------------------------------- /second-edition/en/src/img/trpl14-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/en/src/img/trpl14-02.png -------------------------------------------------------------------------------- /second-edition/en/src/img/trpl14-03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/en/src/img/trpl14-03.png -------------------------------------------------------------------------------- /second-edition/en/src/img/trpl14-04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/en/src/img/trpl14-04.png -------------------------------------------------------------------------------- /second-edition/en/src/img/trpl15-02.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | %3 11 | 12 | 13 | 14 | table0 15 | 16 | Cons 17 | 18 | i32 19 | 20 | 21 | Box 22 | 23 | usize 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /second-edition/en/src/img/trpl20-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/en/src/img/trpl20-01.png -------------------------------------------------------------------------------- /second-edition/en/style-guide.md: -------------------------------------------------------------------------------- 1 | # Style Guide 2 | 3 | ## Prose 4 | 5 | * Prefer title case for chapter/section headings, ex: `## Generating a Secret 6 | Number` rather than `## Generating a secret number`. 7 | * Prefer italics over single quotes when calling out a term, ex: `is an 8 | *associated function* of` rather than `is an ‘associated function’ of`. 9 | * When talking about a method in prose, DO NOT include the parentheses, ex: 10 | `read_line` rather than `read_line()`. 11 | * Hard wrap at 80 chars 12 | * Prefer not mixing code and not-code in one word, ex: ``Remember when we wrote 13 | `use std::io`?`` rather than ``Remember when we `use`d `std::io`?`` 14 | 15 | ## Code 16 | 17 | * Add the file name before markdown blocks to make it clear which file we're 18 | talking about, when applicable. 19 | * When making changes to code, make it clear which parts of the code changed 20 | and which stayed the same... not sure how to do this yet 21 | * Split up long lines as appropriate to keep them under 80 chars if possible 22 | * Use `bash` syntax highlighting for command line output code blocks 23 | 24 | ## Links 25 | 26 | Once all the scripts are done: 27 | 28 | * If a link shouldn't be printed, mark it to be ignored 29 | * This includes all "Chapter XX" intra-book links, which *should* be links 30 | for the HTML version 31 | * Make intra-book links and stdlib API doc links relative so they work whether 32 | the book is read offline or on docs.rust-lang.org 33 | * Use markdown links and keep in mind that they will be changed into `text at 34 | *url*` in print, so word them in a way that it reads well in that format 35 | -------------------------------------------------------------------------------- /second-edition/es/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rust-book" 3 | version = "0.0.1" 4 | authors = ["Steve Klabnik "] 5 | description = "The Rust Book" 6 | 7 | [[bin]] 8 | name = "concat_chapters" 9 | path = "tools/src/bin/concat_chapters.rs" 10 | 11 | [[bin]] 12 | name = "lfp" 13 | path = "tools/src/bin/lfp.rs" 14 | 15 | [[bin]] 16 | name = "link2print" 17 | path = "tools/src/bin/link2print.rs" 18 | 19 | [[bin]] 20 | name = "remove_links" 21 | path = "tools/src/bin/remove_links.rs" 22 | 23 | [[bin]] 24 | name = "remove_markup" 25 | path = "tools/src/bin/remove_markup.rs" 26 | 27 | [[bin]] 28 | name = "convert_quotes" 29 | path = "tools/src/bin/convert_quotes.rs" 30 | 31 | [dependencies] 32 | walkdir = "0.1.5" 33 | docopt = "0.6.82" 34 | rustc-serialize = "0.3.19" 35 | regex = "0.1.73" 36 | lazy_static = "0.2.1" 37 | -------------------------------------------------------------------------------- /second-edition/es/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010-2017 The Rust Project Developers 2 | 3 | Permission is hereby granted, free of charge, to any 4 | person obtaining a copy of this software and associated 5 | documentation files (the "Software"), to deal in the 6 | Software without restriction, including without 7 | limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software 10 | is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice 14 | shall be included in all copies or substantial portions 15 | of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 18 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 19 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 24 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. 26 | -------------------------------------------------------------------------------- /second-edition/es/book.toml: -------------------------------------------------------------------------------- 1 | [book] 2 | title = "The Rust Programming Language" 3 | author = "Steve Klabnik and Carol Nichols, with Contributions from the Rust Community" 4 | -------------------------------------------------------------------------------- /second-edition/es/convert-quotes.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2017 The Rust Project Developers. See the COPYRIGHT 3 | # file at the top-level directory of this distribution and at 4 | # http://rust-lang.org/COPYRIGHT. 5 | # 6 | # Licensed under the Apache License, Version 2.0 or the MIT license 8 | # , at your 9 | # option. This file may not be copied, modified, or distributed 10 | # except according to those terms. 11 | 12 | set -eu 13 | 14 | dir=$1 15 | 16 | mkdir -p "tmp/$dir" 17 | 18 | for f in $dir/*.md 19 | do 20 | cat "$f" | cargo run --bin convert_quotes > "tmp/$f" 21 | mv "tmp/$f" "$f" 22 | done 23 | -------------------------------------------------------------------------------- /second-edition/es/doc-to-md.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2016 The Rust Project Developers. See the COPYRIGHT 3 | # file at the top-level directory of this distribution and at 4 | # http://rust-lang.org/COPYRIGHT. 5 | # 6 | # Licensed under the Apache License, Version 2.0 or the MIT license 8 | # , at your 9 | # option. This file may not be copied, modified, or distributed 10 | # except according to those terms. 11 | 12 | set -eu 13 | 14 | # Get all the docx files in the tmp dir, 15 | ls tmp/*.docx | \ 16 | # Extract just the filename so we can reuse it easily. 17 | xargs -n 1 basename -s .docx | \ 18 | while IFS= read -r filename; do 19 | # Make a directory to put the XML in 20 | mkdir -p "tmp/$filename" 21 | # Unzip the docx to get at the xml 22 | unzip -o "tmp/$filename.docx" -d "tmp/$filename" 23 | # Convert to markdown with XSL 24 | xsltproc tools/docx-to-md.xsl "tmp/$filename/word/document.xml" | \ 25 | # Hard wrap at 80 chars at word bourdaries 26 | fold -w 80 -s | \ 27 | # Remove trailing whitespace & save in the nostarch dir for comparison 28 | sed -e "s/ *$//" > "nostarch/$filename.md" 29 | done 30 | -------------------------------------------------------------------------------- /second-edition/es/dot/trpl04-01.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | rankdir=LR; 3 | overlap=false; 4 | dpi=300.0; 5 | node [shape="plaintext"]; 6 | 7 | table0[label=< 8 | 9 | 10 | 11 | 12 | 13 |
s1
namevalue
ptr
len5
capacity5
>]; 14 | table1[label=< 15 | 16 | 17 | 18 | 19 | 20 | 21 |
indexvalue
0h
1e
2l
3l
4o
>]; 22 | 23 | edge[tailclip="false"]; 24 | table0:pointer:c -> table1:pointee; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /second-edition/es/dot/trpl04-02.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | rankdir=LR; 3 | overlap=false; 4 | dpi=300.0; 5 | node [shape="plaintext"]; 6 | 7 | table0[label=< 8 | 9 | 10 | 11 | 12 | 13 |
s1
namevalue
ptr
len5
capacity5
>]; 14 | table3[label=< 15 | 16 | 17 | 18 | 19 | 20 |
s2
namevalue
ptr
len5
capacity5
>]; 21 | 22 | table1[label=< 23 | 24 | 25 | 26 | 27 | 28 | 29 |
indexvalue
0h
1e
2l
3l
4o
>]; 30 | 31 | edge[tailclip="false"]; 32 | table0:pointer:c -> table1:pointee; 33 | table3:pointer:c -> table1:pointee; 34 | } 35 | 36 | -------------------------------------------------------------------------------- /second-edition/es/dot/trpl04-03.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | rankdir=LR; 3 | overlap=false; 4 | dpi=300.0; 5 | node [shape="plaintext"]; 6 | 7 | table0[label=< 8 | 9 | 10 | 11 | 12 | 13 |
s2
namevalue
ptr
len5
capacity5
>]; 14 | table1[label=< 15 | 16 | 17 | 18 | 19 | 20 | 21 |
indexvalue
0h
1e
2l
3l
4o
>]; 22 | 23 | table3[label=< 24 | 25 | 26 | 27 | 28 | 29 |
s1
namevalue
ptr
len5
capacity5
>]; 30 | table4[label=< 31 | 32 | 33 | 34 | 35 | 36 | 37 |
indexvalue
0h
1e
2l
3l
4o
>]; 38 | 39 | 40 | edge[tailclip="false"]; 41 | table0:pointer:c -> table1:pointee; 42 | table3:pointer:c -> table4:pointee; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /second-edition/es/dot/trpl04-04.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | rankdir=LR; 3 | overlap=false; 4 | dpi=300.0; 5 | node [shape="plaintext"]; 6 | 7 | table0[label=< 8 | 9 | 10 | 11 | 12 | 13 |
s1
namevalue
ptr
len5
capacity5
>]; 14 | table3[label=< 15 | 16 | 17 | 18 | 19 | 20 |
s2
namevalue
ptr
len5
capacity5
>]; 21 | 22 | table1[label=< 23 | 24 | 25 | 26 | 27 | 28 | 29 |
indexvalue
0h
1e
2l
3l
4o
>]; 30 | 31 | edge[tailclip="false"]; 32 | table0:pointer:c -> table1:pointee; 33 | table3:pointer:c -> table1:pointee; 34 | } 35 | 36 | -------------------------------------------------------------------------------- /second-edition/es/dot/trpl04-05.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | rankdir=LR; 3 | overlap=false; 4 | dpi=300.0; 5 | node [shape="plaintext"]; 6 | 7 | table0[label=< 8 | 9 | 10 | 11 |
s
namevalue
ptr
>]; 12 | table1[label=< 13 | 14 | 15 | 16 | 17 | 18 |
s1
namevalue
ptr
len5
capacity5
>]; 19 | table2[label=< 20 | 21 | 22 | 23 | 24 | 25 | 26 |
indexvalue
0h
1e
2l
3l
4o
>]; 27 | 28 | edge[tailclip="false"]; 29 | table1:pointer:c -> table2:pointee; 30 | table0:borrower:c -> table1:borrowee; 31 | } 32 | 33 | -------------------------------------------------------------------------------- /second-edition/es/dot/trpl04-06.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | rankdir=LR; 3 | overlap=false; 4 | dpi=300.0; 5 | node [shape="plaintext"]; 6 | 7 | table0[label=< 8 | 9 | 10 | 11 | 12 |
world
namevalue
ptr
len5
>]; 13 | 14 | table3[label=< 15 | 16 | 17 | 18 | 19 | 20 |
s
namevalue
ptr
len11
capacity11
>]; 21 | table4[label=< 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 |
indexvalue
0h
1e
2l
3l
4o
5
6w
7o
8r
9l
10d
>]; 35 | 36 | 37 | edge[tailclip="false"]; 38 | table0:pointer2:c -> table4:pointee2; 39 | table3:pointer:c -> table4:pointee; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /second-edition/es/dot/trpl15-01.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | rankdir=LR; 3 | overlap=false; 4 | dpi=300.0; 5 | node [shape="plaintext"]; 6 | 7 | table0[label=< 8 | 9 | 22 |
Cons
i32 10 | 11 | 21 |
Cons
i32 12 | 13 | 20 |
Cons
i32 14 | 15 | 19 |
Cons
i32 16 | 17 | 18 |
Cons
i32
>]; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /second-edition/es/dot/trpl15-02.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | rankdir=LR; 3 | overlap=false; 4 | dpi=300.0; 5 | node [shape="plaintext"]; 6 | 7 | table0[label=< 8 | 9 | 10 | 16 |
Cons
i32 11 | 12 | 13 | 14 |
Box
usize
15 |
>]; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /second-edition/es/dot/trpl15-03.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | rankdir=LR; 3 | overlap=false; 4 | dpi=300.0; 5 | node [shape="plaintext"]; 6 | 7 | table4[label=< 8 | 9 |
b
>]; 10 | 11 | table5[label=< 12 | 13 |
3
>]; 14 | 15 | 16 | table0[label=< 17 | 18 |
a
>]; 19 | 20 | table1[label=< 21 | 22 |
5
>]; 23 | 24 | table2[label=< 25 | 26 |
10
>]; 27 | 28 | table3[label=< 29 | 30 |
Nil
>]; 31 | 32 | 33 | table6[label=< 34 | 35 |
c
>]; 36 | 37 | table7[label=< 38 | 39 |
4
>]; 40 | 41 | 42 | edge[tailclip="false"]; 43 | table0:ptr0:c -> table1:pte0; 44 | table1:ptr1:c -> table2:pte1; 45 | table2:ptr2:c -> table3:pte2; 46 | table4:ptr4:c -> table5:pte4; 47 | table5:ptr5:c -> table1:pte0; 48 | table6:ptr6:c -> table7:pte6; 49 | table7:ptr7:c -> table1:pte0; 50 | } 51 | 52 | -------------------------------------------------------------------------------- /second-edition/es/nostarch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2016 The Rust Project Developers. See the COPYRIGHT 3 | # file at the top-level directory of this distribution and at 4 | # http://rust-lang.org/COPYRIGHT. 5 | # 6 | # Licensed under the Apache License, Version 2.0 or the MIT license 8 | # , at your 9 | # option. This file may not be copied, modified, or distributed 10 | # except according to those terms. 11 | 12 | set -eu 13 | 14 | cargo build --release 15 | 16 | mkdir -p tmp 17 | rm -rf tmp/*.md 18 | 19 | # Get all the markdown files in the src dir, 20 | ls src/${1:-""}*.md | \ 21 | # except for SUMMARY.md. 22 | grep -v SUMMARY.md | \ 23 | # Extract just the filename so we can reuse it easily. 24 | xargs -n 1 basename | \ 25 | # Remove all links followed by , then 26 | # Change all remaining links from markdown to italicized inline text. 27 | while IFS= read -r filename; do 28 | < "src/$filename" ./target/release/remove_links \ 29 | | ./target/release/link2print \ 30 | | ./target/release/remove_markup > "tmp/$filename" 31 | done 32 | # Concat the files into the nostarch dir. 33 | ./target/release/concat_chapters tmp nostarch 34 | -------------------------------------------------------------------------------- /second-edition/es/nostarch/odt/appendix.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/es/nostarch/odt/appendix.docx -------------------------------------------------------------------------------- /second-edition/es/nostarch/odt/chapter00.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/es/nostarch/odt/chapter00.docx -------------------------------------------------------------------------------- /second-edition/es/nostarch/odt/chapter01.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/es/nostarch/odt/chapter01.docx -------------------------------------------------------------------------------- /second-edition/es/nostarch/odt/chapter02.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/es/nostarch/odt/chapter02.doc -------------------------------------------------------------------------------- /second-edition/es/nostarch/odt/chapter03.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/es/nostarch/odt/chapter03.docx -------------------------------------------------------------------------------- /second-edition/es/nostarch/odt/chapter04.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/es/nostarch/odt/chapter04.docx -------------------------------------------------------------------------------- /second-edition/es/nostarch/odt/chapter05.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/es/nostarch/odt/chapter05.docx -------------------------------------------------------------------------------- /second-edition/es/nostarch/odt/chapter06.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/es/nostarch/odt/chapter06.docx -------------------------------------------------------------------------------- /second-edition/es/nostarch/odt/chapter07.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/es/nostarch/odt/chapter07.docx -------------------------------------------------------------------------------- /second-edition/es/nostarch/odt/chapter08.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/es/nostarch/odt/chapter08.docx -------------------------------------------------------------------------------- /second-edition/es/nostarch/odt/chapter09.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/es/nostarch/odt/chapter09.docx -------------------------------------------------------------------------------- /second-edition/es/nostarch/odt/chapter10.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/es/nostarch/odt/chapter10.docx -------------------------------------------------------------------------------- /second-edition/es/nostarch/odt/chapter11.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/es/nostarch/odt/chapter11.docx -------------------------------------------------------------------------------- /second-edition/es/nostarch/odt/chapter12.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/es/nostarch/odt/chapter12.docx -------------------------------------------------------------------------------- /second-edition/es/nostarch/odt/chapter13.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/es/nostarch/odt/chapter13.docx -------------------------------------------------------------------------------- /second-edition/es/nostarch/odt/chapter14.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/es/nostarch/odt/chapter14.docx -------------------------------------------------------------------------------- /second-edition/es/nostarch/odt/chapter15.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/es/nostarch/odt/chapter15.docx -------------------------------------------------------------------------------- /second-edition/es/nostarch/odt/chapter16.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/es/nostarch/odt/chapter16.docx -------------------------------------------------------------------------------- /second-edition/es/nostarch/odt/chapter17.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/es/nostarch/odt/chapter17.docx -------------------------------------------------------------------------------- /second-edition/es/nostarch/odt/chapter18.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/es/nostarch/odt/chapter18.docx -------------------------------------------------------------------------------- /second-edition/es/nostarch/odt/chapter19.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/es/nostarch/odt/chapter19.docx -------------------------------------------------------------------------------- /second-edition/es/nostarch/odt/chapter20.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/es/nostarch/odt/chapter20.docx -------------------------------------------------------------------------------- /second-edition/es/nostarch/odt/index.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/es/nostarch/odt/index.docx -------------------------------------------------------------------------------- /second-edition/es/src/appendix-00.md: -------------------------------------------------------------------------------- 1 | # Apéndice 2 | 3 | Las siguientes secciones contienen material de referencia 4 | que puede serle útil en su viaje a Rust. -------------------------------------------------------------------------------- /second-edition/es/src/appendix-05-translation.md: -------------------------------------------------------------------------------- 1 | ## Appendix E: Translations of the Book 2 | 3 | For resources in languages other than English. Most are still in progress; see 4 | [the Translations label][label] to help or let us know about a new translation! 5 | 6 | [label]: https://github.com/rust-lang/book/issues?q=is%3Aopen+is%3Aissue+label%3ATranslations 7 | 8 | - [Português](https://github.com/rust-br/rust-book-pt-br) (BR) 9 | - [Português](https://github.com/nunojesus/rust-book-pt-pt) (PT) 10 | - [Tiếng việt](https://github.com/hngnaig/rust-lang-book/tree/vi-VN) 11 | - [简体中文](http://www.broadview.com.cn/article/144), [alternate](https://github.com/KaiserY/trpl-zh-cn) 12 | - [Українська](https://github.com/pavloslav/rust-book-uk-ua) 13 | - [Español](https://github.com/thecodix/book) 14 | - [Italiano](https://github.com/AgeOfWar/rust-book-it) 15 | - [Русский](https://github.com/iDeBugger/rust-book-ru) 16 | - [한국어](https://github.com/rinthel/rust-lang-book-ko) 17 | - [日本語](https://github.com/hazama-yuinyan/book) 18 | - [Français](https://github.com/quadrifoglio/rust-book-fr) 19 | - [Polski](https://github.com/paytchoo/book-pl) 20 | - [עברית](https://github.com/idanmel/rust-book-heb) 21 | - [Cebuano](https://github.com/agentzero1/book) 22 | - [Tagalog](https://github.com/josephace135/book) 23 | -------------------------------------------------------------------------------- /second-edition/es/src/ch01-00-getting-started.md: -------------------------------------------------------------------------------- 1 | # Empezando 2 | 3 | ¡Comencemos tu viaje a Rust! Hay mucho que aprender, pero 4 | cada viaje comienza en alguna parte. En este capítulo, discutiremos: 5 | 6 | * Instalación de Rust en Linux, macOS y Windows 7 | * Escribir un programa que imprime `Hello, world!` 8 | * Usando `cargo`, el administrador de paquetes de Rust y 9 | el sistema de compilación 10 | -------------------------------------------------------------------------------- /second-edition/es/src/ch03-00-common-programming-concepts.md: -------------------------------------------------------------------------------- 1 | # Conceptos comunes de programación 2 | 3 | Este capítulo cubre conceptos que aparecen en casi todos los lenguajes de 4 | programación y cómo funcionan en Rust. Muchos lenguajes de programación 5 | tienen mucho en común en su núcleo. Ninguno de los conceptos presentados en 6 | este capítulo son exclusivos de Rust, pero los discutiremos en el contexto de 7 | Rust y explicaremos las convenciones sobre el uso de estos conceptos. 8 | 9 | Específicamente, aprenderá sobre variables, tipos básicos, funciones, 10 | comentarios y flujo de control. Estas fundaciones estarán en cada programa de 11 | Rust, y aprenderlas temprano te dará un núcleo fuerte para empezar. 12 | 13 | > ### Palabras clave 14 | > 15 | > El lenguaje Rust tiene un conjunto de *palabras clave* que están reservadas 16 | > para el uso exclusivo del lenguaje, al igual que en otros lenguajes. Tenga 17 | > en cuenta que no puede usar estas palabras como nombres de variables o 18 | > funciones. La mayoría de las palabras clave tienen un significado especial, 19 | > y las usará para realizar diversas tareas en sus programas de Rust; algunos 20 | > no tienen ninguna funcionalidad actual asociada pero se han reservado para 21 | > la funcionalidad que podría agregarse a Rust en el futuro. Puede encontrar 22 | > una lista de palabras clave en el Apéndice A. -------------------------------------------------------------------------------- /second-edition/es/src/ch03-04-comments.md: -------------------------------------------------------------------------------- 1 | ## Comentarios 2 | 3 | Todos los programadores se esfuerzan por hacer que su código sea fácil de 4 | entender, pero a veces una explicación adicional está justificada. En estos casos, 5 | los programadores dejan notas, o *comentarios*, en su código fuente que el compilador 6 | ignorará pero para la gente que lea el código fuente le puede ser útil. 7 | 8 | Aquí hay un comentario simple: 9 | 10 | ```rust 11 | // hello, world 12 | ``` 13 | 14 | En Rust, los comentarios deben comenzar con dos barras y continuar hasta el fin de 15 | línea. Para comentarios que se extienden más allá de una sola línea, deberá incluir 16 | `//` en cada línea, así: 17 | 18 | ```rust 19 | // So we’re doing something complicated here, long enough that we need 20 | // multiple lines of comments to do it! Whew! Hopefully, this comment will 21 | // explain what’s going on. 22 | ``` 23 | 24 | Los comentarios también pueden colocarse al final de las líneas que contienen el código: 25 | 26 | Filename: src/main.rs 27 | 28 | ```rust 29 | fn main() { 30 | let lucky_number = 7; // I’m feeling lucky today 31 | } 32 | ``` 33 | 34 | Pero con mayor frecuencia los verá usar en el siguiente formato, con el comentario 35 | en un línea separada sobre el código que está anotando: 36 | 37 | Filename: src/main.rs 38 | 39 | ```rust 40 | fn main() { 41 | // I’m feeling lucky today 42 | let lucky_number = 7; 43 | } 44 | ``` 45 | 46 | Rust también tiene otro tipo de comentario, comentarios de documentación, que 47 | trataremos en el Capítulo 14. 48 | -------------------------------------------------------------------------------- /second-edition/es/src/ch04-00-understanding-ownership.md: -------------------------------------------------------------------------------- 1 | # Comprender la propiedad (Ownership) 2 | 3 | La propiedad (*Ownership*), es la característica más exclusiva de Rust, y permite a Rust hacer 4 | garantías en la seguridad de la memoria sin necesidad de un recolector de basura. 5 | Por lo tanto, es importante entender cómo funciona la propiedad en Rust. En este 6 | capítulo, vamos a hablar sobre la propiedad, así como varias características relacionadas: 7 | préstamos (*borrowing*), rebanadas (*slices*), y cómo Rust establece los datos en la memoria. 8 | -------------------------------------------------------------------------------- /second-edition/es/src/ch05-00-structs.md: -------------------------------------------------------------------------------- 1 | # Usar *Structs* para estructurar datos relacionados 2 | 3 | Un *struc *, o *structure*, es un tipo de datos personalizado que le permite 4 | nombrar y agrupar varios valores relacionados que conforman un grupo significativo. 5 | Si está familiarizado con un lenguaje orientado a objetos, a *struct* es como los 6 | atributos de datos de un objeto. En este capítulo, compararemos y contrastaremos 7 | *tuplas* con *structs*, demostraremos cómo usar *structs* y veremos cómo definir 8 | métodos y funciones asociadas para especificar el comportamiento asociado con los 9 | datos de un *structs*. Los *structs* y los *enums* (explicadas en el Capítulo 6) 10 | son los componentes básicos para crear nuevos tipos en el dominio de su programa 11 | para aprovechar al máximo la comprobación de tipos en tiempo de compilación de Rust. 12 | -------------------------------------------------------------------------------- /second-edition/es/src/ch06-00-enums.md: -------------------------------------------------------------------------------- 1 | # Enums y patrones de *concordancias * 2 | 3 | En este capítulo veremos *enumerations* (*enumeraciones*), también conocidas como *enums*. 4 | Los enumeraciones le permiten definir un tipo enumerando sus posibles valores. 5 | Primero, definiremos y usaremos una enumeración para mostrar cómo una enumeración puede 6 | codificar el significado junto con los datos. A continuación, exploraremos una enumeración 7 | particularmente útil, llamada `Opción`, que expresa que un valor puede ser algo o nada. 8 | Luego veremos cómo la coincidencia de patrones en la expresión `match` hace que sea fácil 9 | ejecutar código diferente para diferentes valores de una enumeración. Finalmente, cubriremos 10 | cómo el constructo `if let` es otro idioma conveniente y conciso disponible para manejar 11 | enumeraciones en su código. 12 | 13 | Los *enums* son una característica en muchos lenguajes, pero sus capacidades difieren 14 | en algunos de ellos. Las enumeraciones de Rust son más similares a *tipos de datos algebraicos* 15 | (*algebraic data types*) en lenguajes funcionales, como F#, OCaml y Haskell. 16 | -------------------------------------------------------------------------------- /second-edition/es/src/ch07-00-modules.md: -------------------------------------------------------------------------------- 1 | # Utilizando módulos para reutilizar y organizar código 2 | 3 | Cuando comiences a escribir programas en Rust, tu código podría vivir únicamente en la función `main`. A medida que su código crezca, eventualmente moverá la funcionalidad a otras funciones para su reutilización y una mejor organización. Al dividir tu código en fragmentos más pequeños, haces que cada trozo sea más fácil de entender por sí mismo. Pero, ¿qué sucede si tienes demasiadas funciones?Rust tiene un sistema modular que permite la reutilización de código de manera organizada. 4 | 5 | De la misma manera que extraes líneas de código en una función, puedes extraer funciones (y otro código, como estructuras y enumeraciones) de diferentes módulos. Un *módulo* es un *espacio de nombres* (*namespace*) que contiene definiciones de funciones o tipos, y usted puede elegir si esas definiciones son visibles fuera de su módulo (público) o no (privado). Aquí hay una descripción general de cómo funcionan los módulos: 6 | 7 | * La palabra clave `mod` declara un nuevo módulo. El código dentro del módulo aparece inmediatamente después de esta declaración entre llaves o en otro archivo. 8 | * Por defecto, las funciones, tipos, constantes y módulos son privados. La palabra clave `pub` hace que un elemento sea público y, por lo tanto, visible fuera de su espacio de nombres. 9 | * La palabra clave `use` trae los módulos, o las definiciones dentro de los módulos, al alcance, por lo que es más fácil referirse a ellos. 10 | 11 | Veremos cada una de estas partes para ver cómo encajan en el todo. 12 | -------------------------------------------------------------------------------- /second-edition/es/src/ch08-00-common-collections.md: -------------------------------------------------------------------------------- 1 | # Colecciones comunes 2 | 3 | La biblioteca estándar de Rust incluye varias estructuras de datos muy útiles 4 | llamadas *colecciones*. La mayoría de los otros tipos de datos representan un 5 | valor específico, pero las colecciones pueden contener múltiples valores. A 6 | diferencia de los tipos de matriz y tupla incorporados, los datos a los que 7 | apuntan estas colecciones se almacenan en el montículo (*heap*), lo que 8 | significa que no 9 | es necesario conocer la cantidad de datos en tiempo de compilación y pueden 10 | aumentar o disminuir a medida que se ejecuta el programa. Cada tipo de 11 | colección tiene diferentes capacidades y costos, y elegir uno apropiado para 12 | su situación actual es una habilidad que desarrollará con el tiempo. En este 13 | capítulo, analizaremos tres colecciones que se utilizan muy a menudo en los 14 | programas de Rust: 15 | 16 | * Un *vector* le permite almacenar un número variable de valores uno al lado 17 | del otro. 18 | * Un *string* es una colección de caracteres. Ya hemos mencionado el tipo 19 | `String` anteriormente, pero en este capítulo hablaremos en profundidad. 20 | * Un *hash map* le permite asociar un valor con una clave particular. Es una 21 | implementación particular de la estructura de datos más general llamada 22 | *map*. 23 | 24 | Para conocer los otros tipos de colecciones proporcionadas por la biblioteca estándar, consulte [la documentación][collections]. 25 | 26 | [collections]: ../../std/collections/index.html 27 | 28 | Discutiremos cómo crear y actualizar *vectores*, *strings* y *mapas hash*, así como también lo que hace que cada especial. -------------------------------------------------------------------------------- /second-edition/es/src/ch09-00-error-handling.md: -------------------------------------------------------------------------------- 1 | # Manejo de errores 2 | 3 | El compromiso de Rust con la confiabilidad se extiende al manejo de errores. 4 | Los errores son un hecho de la vida en el software, por lo que Rust tiene una 5 | serie de características para manejar situaciones en las que algo sale mal. 6 | En muchos casos, Rust requiere que reconozcas la posibilidad de un error y 7 | actúes antes de compilar el código. Este requisito hace que su programa sea 8 | más robusto al garantizar que descubrirá los errores y los manejará 9 | adecuadamente antes de implementar su código en producción. 10 | 11 | Rust agrupa los errores en dos categorías principales: *recuperables* y 12 | *errores irrecuperables*. Para un error recuperable, como un error de archivo 13 | no encontrado, es razonable informar el problema al usuario y volver a 14 | intentar la operación. Los errores irrecuperables son siempre síntomas de 15 | errores, como intentar acceder a una ubicación más allá del final de una 16 | matriz. 17 | 18 | La mayoría de los lenguajes no distinguen entre estos dos tipos de errores y 19 | manejan ambos de la misma manera, usando mecanismos como excepciones. Rust no 20 | tiene excepciones. En cambio, tiene el tipo `Result ` para los errores 21 | recuperables y la macro `panic!` Que detiene la ejecución cuando el programa 22 | encuentra un error irrecuperable. Este capítulo cubre la invocación de 23 | `panic!` Primero y luego habla sobre la devolución de los valores 24 | `Result `. Además, exploraremos consideraciones al decidir si 25 | intentamos recuperarnos de un error o detener la ejecución. 26 | -------------------------------------------------------------------------------- /second-edition/es/src/ch13-00-functional-features.md: -------------------------------------------------------------------------------- 1 | # Características del lenguaje funcional: *Iterators* y *Closures* 2 | 3 | El diseño de Rust se ha inspirado en muchos lenguajes y técnicas existentes, 4 | y una influencia significativa es la *programación funcional*. La 5 | programación en un estilo funcional a menudo incluye el uso de funciones como 6 | valores pasándolos en argumentos, regresándolos de otras funciones, 7 | asignándolos a variables para su posterior ejecución, y así sucesivamente. 8 | 9 | En este capítulo, no debatiremos el tema de qué programación funcional es o 10 | no será, sino que discutiremos algunas características de Rust que son 11 | similares a las características en muchos lenguajes que a menudo se denominan 12 | funcionales. 13 | 14 | Más específicamente, cubriremos: 15 | 16 | * *Closures*, una construcción similar a una función que puedes almacenar en una variable 17 | * *Iteradores*, una forma de procesar una serie de elementos 18 | * Cómo utilizar estas dos características para mejorar el proyecto de E/S en 19 | el Capítulo 12 20 | * El rendimiento de estas dos características (alerta de spoiler: ¡son más 21 | rápidos de lo que crees!) 22 | 23 | Otras características de Rust, como la *coincidencia de patrones* 24 | (*pattern matching*) y las enumeraciones, que hemos cubierto en otros 25 | capítulos, también están influenciadas por el estilo funcional. Dominar los 26 | *Closures* y los *Iterators* (*Iteradores*) es una parte importante de la 27 | redacción del código Rust idiomático y rápido, por lo que les dedicaremos 28 | todo este capítulo. -------------------------------------------------------------------------------- /second-edition/es/src/ch14-00-more-about-cargo.md: -------------------------------------------------------------------------------- 1 | # Más sobre Cargo y Crates.io 2 | 3 | Hasta ahora solo hemos utilizado las funciones más básicas de Cargo para 4 | construir, ejecutar y probar nuestro código, pero puede hacer mucho más. En 5 | este capítulo, analizaremos algunas de sus otras funciones más avanzadas para 6 | mostrarle cómo hacer lo siguiente: 7 | 8 | * Personaliza tu compilación a través de los perfiles de lanzamiento 9 | * Publicar bibliotecas en [crates.io] (https://crates.io) 10 | * Organiza grandes proyectos con espacios de trabajo 11 | * Instalar binarios desde [crates.io] (https://crates.io) 12 | * Extender carga utilizando comandos personalizados 13 | 14 | Cargo puede hacer incluso más de lo que cubrimos en este capítulo, así que para una explicación completa de todas sus características, vea 15 | [itsdocumentation](https://doc.rust-lang.org/cargo/). 16 | -------------------------------------------------------------------------------- /second-edition/es/src/ch14-05-extending-cargo.md: -------------------------------------------------------------------------------- 1 | ## Extender *Cargo* con comandos personalizados 2 | 3 | Cargo está diseñado para que pueda ampliarlo con nuevos subcomandos sin tener 4 | que modificar Cargo. Si un binario en su `$PATH` se llama `cargo-something`, 5 | puede ejecutarlo como si fuera un subcomando Cargo ejecutando 6 | `cargo something`. Los comandos personalizados como este también se enumeran 7 | cuando ejecuta `cargo-list`. ¡Poder usar `cargo install` para instalar 8 | extensiones y luego ejecutarlas al igual que las herramientas de Cargo 9 | incorporadas es un beneficio súper conveniente del diseño de Cargo. 10 | 11 | ## Resumen 12 | 13 | Compartir código con Cargo y [crates.io](https://crates.io) 14 | es parte de lo que hace que el ecosistema de Rust sea útil para muchas tareas 15 | diferentes. La biblioteca estándar de Rust es pequeña y estable, pero los 16 | *crates* son fáciles de compartir, usar y mejorar en una línea de tiempo 17 | diferente a la del lenguaje. No tenga miedo de compartir el código que le sea 18 | útil en [crates.io](https://crates.io) ; ¡es probable que 19 | también sea útil para otra persona! 20 | -------------------------------------------------------------------------------- /second-edition/es/src/ch17-00-oop.md: -------------------------------------------------------------------------------- 1 | # Características de programación orientadas a objetos de Rust 2 | 3 | La programación orientada a objetos (OOP) es una forma de modelar programas. 4 | Los objetos vinieron de Simula en la década de 1960. Esos objetos influyeron 5 | en la arquitectura de programación de Alan Kay en la que los objetos se 6 | transmiten mensajes entre sí. Él acuñó el término *programación orientada a objetos* en 1967 para describir esta arquitectura. Muchas definiciones 7 | competitivas describen qué OOP es; algunas definiciones clasificaron a Rust 8 | como orientado a objetos, pero otras definiciones no lo harían. En este 9 | capítulo, exploraremos ciertas características que comúnmente se consideran 10 | orientadas a objetos y cómo esas características se traducen en Rust 11 | idiomático. Luego le mostraremos cómo implementar un patrón de diseño 12 | orientado a objetos en Rust y discutiremos las ventajas y desventajas de 13 | hacerlo en lugar de implementar una solución utilizando algunas de las 14 | fortalezas de Rust. 15 | -------------------------------------------------------------------------------- /second-edition/es/src/ch18-00-patterns.md: -------------------------------------------------------------------------------- 1 | # Patterns and Matching 2 | 3 | Los patrones son una sintaxis especial en Rust para hacer coincidir con la 4 | estructura de tipos, tanto complejos como simples. El uso de patrones junto 5 | con las expresiones `match` y otras construcciones le da más control sobre el 6 | flujo de control de un programa. Un patrón consiste en una combinación de los 7 | siguientes: 8 | 9 | * Literals 10 | * Destructured arrays, enums, structs, or tuples 11 | * Variables 12 | * Wildcards 13 | * Placeholders 14 | 15 | Estos componentes describen la forma de los datos con los que estamos 16 | trabajando, y luego los comparamos con los valores para determinar si nuestro 17 | programa tiene los datos correctos para continuar ejecutando un fragmento de 18 | código en particular. 19 | 20 | Para usar un patrón, lo comparamos con algún valor. Si el patrón coincide con 21 | el valor, usamos las partes de valor en nuestro código. Recuerde las 22 | expresiones `match` en el Capítulo 6 que utilizan patrones, como el ejemplo 23 | de la máquina clasificadora de monedas. Si el valor se ajusta a la forma del 24 | patrón, podemos usar las piezas nombradas. Si no lo hace, el código asociado 25 | con el patrón no se ejecutará. 26 | 27 | Este capítulo es una referencia sobre todo lo relacionado con patrones. 28 | Cubriremos los lugares válidos para usar patrones, la diferencia entre 29 | patrones refutables e irrefutables y los diferentes tipos de sintaxis de 30 | patrones que podría ver. Al final del capítulo, sabrá cómo usar patrones para 31 | expresar muchos conceptos de una manera clara. -------------------------------------------------------------------------------- /second-edition/es/src/ch19-00-advanced-features.md: -------------------------------------------------------------------------------- 1 | # Características avanzadas 2 | 3 | Hasta ahora, ha aprendido las partes más comúnmente usadas del lenguaje de 4 | programación Rust. Antes de hacer un proyecto más en el Capítulo 20, veremos 5 | algunos aspectos del lenguaje que puede encontrar de vez en cuando. Puede 6 | usar este capítulo como referencia para cuando encuentre incógnitas cuando 7 | use Rust. Las características que aprenderá a usar en este capítulo son 8 | útiles en situaciones muy específicas. Aunque es posible que no los busque 9 | con frecuencia, queremos asegurarnos de que comprende todas las 10 | características que Rust tiene para ofrecer. 11 | 12 | En este capítulo, cubriremos: 13 | 14 | * Unsafe Rust: cómo desvincularse de algunas de las garantías de Rust y 15 | asumir la responsabilidad de mantener manualmente esas garantías 16 | * *Lifetimes* avanzada: sintaxis para situaciones complejas con *lifetime* 17 | * *Traits* avanzados: tipos asociados, parámetros de tipo predeterminados, 18 | sintaxis completa, supertraits y el nuevo patrón de tipo en relación con los 19 | *trait* 20 | * Tipos avanzados: más sobre el nuevo tipo de patrón, los alias de tipo, el 21 | nunca tipo y los tipos de tamaño dinámico 22 | * Funciones avanzadas y *closures*: *function pointers* y *returning closures* 23 | 24 | ¡Es una colección de características de Rust con algo para todos! ¡Vamos a sumergirnos! 25 | -------------------------------------------------------------------------------- /second-edition/es/src/ch20-00-final-project-a-web-server.md: -------------------------------------------------------------------------------- 1 | # Proyecto final: creación de un servidor web multiproceso 2 | 3 | Ha sido un largo viaje, pero hemos llegado al final del libro. En este capítulo, construiremos un proyecto más juntos para demostrar algunos de los conceptos que cubrimos en los capítulos finales, así como recapitular algunas lecciones anteriores. 4 | 5 | Para nuestro proyecto final, haremos un servidor web que diga "hola" y se parezca a la figura 20-1 en un navegador web. 6 | 7 | ![hello from rust](img/trpl20-01.png) 8 | 9 | Figure 20-1: Nuestro último proyecto compartido 10 | 11 | Aquí está el plan para construir el servidor web: 12 | 13 | 1. Aprende un poco sobre TCP y HTTP. 14 | 2. Escuche las conexiones TCP en un socket. 15 | 3. Analice una pequeña cantidad de solicitudes HTTP. 16 | 4. Crea una respuesta HTTP adecuada. 17 | 5. Mejore el rendimiento de nuestro servidor con un grupo de subprocesos 18 | (*thread pool*). 19 | 20 | Pero antes de comenzar, debemos mencionar un detalle: el método que usaremos 21 | no será la mejor manera de construir un servidor web con Rust. En *https: 22 | //crates.io/* se encuentran disponibles varias *crates* listas para 23 | producción que proporcionan implementaciones más completas de servidor web y 24 | conjunto de subprocesos que las que crearemos. 25 | 26 | Sin embargo, nuestra intención en este capítulo es ayudarlo a aprender, no a 27 | tomar la ruta fácil. Debido a que Rust es un lenguaje de programación de 28 | sistemas, podemos elegir el nivel de abstracción con el que queremos trabajar 29 | y podemos ir a un nivel más bajo de lo que es posible o práctico en otros 30 | lenguajes. Escribiremos el servidor HTTP básico y el grupo de subprocesos 31 | manualmente para que pueda aprender las ideas generales y técnicas detrás de 32 | los *crates* que puede usar en el futuro. 33 | -------------------------------------------------------------------------------- /second-edition/es/src/img/trpl14-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/es/src/img/trpl14-01.png -------------------------------------------------------------------------------- /second-edition/es/src/img/trpl14-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/es/src/img/trpl14-02.png -------------------------------------------------------------------------------- /second-edition/es/src/img/trpl14-03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/es/src/img/trpl14-03.png -------------------------------------------------------------------------------- /second-edition/es/src/img/trpl14-04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/es/src/img/trpl14-04.png -------------------------------------------------------------------------------- /second-edition/es/src/img/trpl15-02.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | %3 11 | 12 | 13 | 14 | table0 15 | 16 | Cons 17 | 18 | i32 19 | 20 | 21 | Box 22 | 23 | usize 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /second-edition/es/src/img/trpl20-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManRR/rust-book-es/a821a22be741a79c20e0de82f73c8e6b04aec5c4/second-edition/es/src/img/trpl20-01.png -------------------------------------------------------------------------------- /second-edition/es/style-guide.md: -------------------------------------------------------------------------------- 1 | # Style Guide 2 | 3 | ## Prose 4 | 5 | * Prefer title case for chapter/section headings, ex: `## Generating a Secret 6 | Number` rather than `## Generating a secret number`. 7 | * Prefer italics over single quotes when calling out a term, ex: `is an 8 | *associated function* of` rather than `is an ‘associated function’ of`. 9 | * When talking about a method in prose, DO NOT include the parentheses, ex: 10 | `read_line` rather than `read_line()`. 11 | * Hard wrap at 80 chars 12 | * Prefer not mixing code and not-code in one word, ex: ``Remember when we wrote 13 | `use std::io`?`` rather than ``Remember when we `use`d `std::io`?`` 14 | 15 | ## Code 16 | 17 | * Add the file name before markdown blocks to make it clear which file we're 18 | talking about, when applicable. 19 | * When making changes to code, make it clear which parts of the code changed 20 | and which stayed the same... not sure how to do this yet 21 | * Split up long lines as appropriate to keep them under 80 chars if possible 22 | * Use `bash` syntax highlighting for command line output code blocks 23 | 24 | ## Links 25 | 26 | Once all the scripts are done: 27 | 28 | * If a link shouldn't be printed, mark it to be ignored 29 | * This includes all "Chapter XX" intra-book links, which *should* be links 30 | for the HTML version 31 | * Make intra-book links and stdlib API doc links relative so they work whether 32 | the book is read offline or on docs.rust-lang.org 33 | * Use markdown links and keep in mind that they will be changed into `text at 34 | *url*` in print, so word them in a way that it reads well in that format 35 | --------------------------------------------------------------------------------