Search engines often show the redirect page for search terms like "rust
topic" or "rust book topic". Currently the redirect targets all go to the
index.html of the second edition of the book. This discourages users
to use the second edition, because many will click on the direct link to
the first edition out of laziness. In addition, as long as the pages of
the second edition are not well linked, the old pages will probably stay
at the top of the search results.
To fix this, this commit changes the target links to go to the related
content in the second edition, in the following way:
Old content maps in different ways to new content:
1. 1:1 mapping
content is comprehensively covered in a single location of the
second edition
2. basic/advanced mapping
content is comprehensively covered in two locations of the second
edition; first location covers the basics, second location covers
advanced topics
3. split mapping
content is covered in muliple locations of the second edition
4. moved
content has moved to another place
5. removed
content doesn't exist in the second edition
This commit handles these cases in the following way:
1. Mapping type 1: 1:1 mapping
Change the link target from "second-edition/index.html" to the
respective chapter, page or section of the second edition.
Change the link text from "Index of the second edition..." to
either of:
- "Related chapter in the second edition"
- "Related page in the second edition"
- "Related section in the second edition"
"Related" was chosen because content of two versions is at least
related but not necessarily equivalent.
Example: closures.md
2. Mapping type 2: basic/advanced mapping
Change the link target from "second-edition/index.html" to the
respective chapter, page or section of the second edition. Add
a second link target for the advanced chapter, page or section.
Change the link text like for type 1. Add the second link with
the following text: "Related chapter in the second edition
of The Rust Programming Language (covering more advanced
topics)". Similar to the messages of type 2 there are variants
with "page" and "section".
Example: lifetimes.md
3. Mapping type 3: split mapping
Change similar to changes for type 2. but add multiple links
with text in parens describing relationship.
4. Mapping type 4: moved
No changes.
Example: compiler-plugins.md
5. Mapping type 5: removed
No changes. See "Improvements" below.
Example: attributes.md
Improvements:
This commit tries to introduce the target links with a minimum of changes.
Copy was adapted only to the extent absolutely necessary. This leaves room
for improvements:
- Better deal with case 3. Describe mapping in copy not only link text.
Actually refer to the links in the body copy.
- Redirect pages of type 5 (content doesn't exist in second edition)
should distinguish between "Content removed for good" and "Content
not ready yet". For the latter category we could link to stub pages.
All the new links were tested manually. The html was produced by a
little script that invokes rustdoc, builds the book and copies
everything into place. The script is not part of this commit.
Here is a list with all mappings:
associated-types.html -1-> ch19-03-advanced-traits.html#associated-types
attributes.html -5-> index.html
bibliography.html -5-> index.html
borrow-and-asref.html -5-> index.html
casting-between-types.html -5-> index.html
choosing-your-guarantees.html ~1~> ch15-00-smart-pointers.html
closures.html -1-> ch13-01-closures.html
comments.html -1-> ch03-04-comments.html
compiler-plugins.html -4-> ../unstable-book/language-features/plugin.html
concurrency.html -1-> ch16-00-concurrency.html
conditional-compilation.html -5-> index.html
const-and-static.html ~1~> ch19-01-unsafe-rust.html#accessing-or-modifying-a-mutable-static-variable
crates-and-modules.html -3-> Modules: ch07-00-modules.html
Crates: ch14-00-more-about-cargo.html
deref-coercions.html ~1~> ch15-02-deref.html#implicit-deref-coercions-with-functions-and-methods
documentation.html ~1~> ch14-02-publishing-to-crates-io.html#making-useful-documentation-comments
drop.html -1-> ch15-03-drop.html
effective-rust.html -5-> index.html
enums.html -1-> ch06-01-defining-an-enum.html
error-handling.html -1-> ch09-00-error-handling.html
ffi.html -1-> ch19-01-unsafe-rust.html#calling-an-unsafe-function-or-method
functions.html -1-> ch03-03-how-functions-work.html
generics.html -1-> ch10-00-generics.html
getting-started.html ~1~> ch01-00-introduction.html
glossary.html -5-> index.html
guessing-game.html -1-> ch02-00-guessing-game-tutorial.html
if-let.html -1-> ch06-03-if-let.html
if.html -1-> ch03-05-control-flow.html#if-expressions
iterators.html -1-> ch13-02-iterators.html
lifetimes.html -2-> ch10-03-lifetime-syntax.html
ch19-02-advanced-lifetimes.html
loops.html -1-> ch03-05-control-flow.html#repetition-with-loops
macros.html -5-> index.html (appendix-05-macros.html is in TOC, but doesn't exist)
match.html -2-> ch06-02-match.html
-2-> ch18-00-patterns.html
method-syntax.html -1-> ch05-03-method-syntax.html
mutability.html -1-> ch03-01-variables-and-mutability.html
operators-and-overloading.html -1-> ch19-03-advanced-traits.html#operator-overloading-and-default-type-parameters
ownership.html -1-> ch04-00-understanding-ownership.html
patterns.html -2-> ch06-02-match.html#patterns-that-bind-to-values
ch18-03-pattern-syntax.html
primitive-types.html ~1~> ch03-02-data-types.html
procedural-macros.html -5-> index.html (appendix-05-macros.html is in TOC, but doesn't exist)
raw-pointers.html ~1~> ch19-01-unsafe-rust.html#dereferencing-a-raw-pointer
references-and-borrowing.html -1-> ch04-02-references-and-borrowing.html
release-channels.html -5-> index.hmtl
strings.html ~2~> ch04-03-slices.html#string-slices [Should be type 3 maybe with distinction &str and String]
~2~> ch08-02-strings.html
structs.html -1-> ch05-00-structs.html
syntax-and-semantics.html ~3~> ch03-00-common-programming-concepts.html
appendix-01-keywords.html
appendix-02-operators.html
appendix-05-macros.html [WIP]
syntax-index.html -5-> index.html
testing.html -1-> ch11-00-testing.html
the-stack-and-the-heap.html -5-> index.html
trait-objects.html -1-> ch17-02-trait-objects.html
traits.html -2-> ch10-02-traits.html
ch19-03-advanced-traits.html
type-aliases.html ~1~> ch19-04-advanced-types.html#type-aliases-create-type-synonyms
ufcs.html -5-> index.html
unsafe.html ~1~> ch19-01-unsafe-rust.html
unsized-types.html ~1~> ch19-04-advanced-types.html#dynamically-sized-types--sized
using-rust-without-the[..].html -5-> index.html
variable-bindings.html -5-> index.html
vectors.html -1-> ch08-01-vectors.html
The Rust Programming Language
This repo contains two editions of “The Rust Programming Language”.
The second edition is a rewrite that will be printed by NoStarch Press, available around October 2017.
You can read it online; the last few chapters aren't completed yet, but the first half of the book is much improved from the first edition. We recommend starting with the second edition.
The first edition is still available to read online.
Requirements
Building the book requires mdBook >= v0.0.13. To get it:
$ cargo install mdbook
Building
To build the book, first cd into either the first-edition or
second-edition directory depending on which edition of the book you would
like to build. Then type:
$ mdbook build
The output will be in the book subdirectory. To check it out, open it in
your web browser.
Firefox:
$ firefox book/index.html # Linux
$ open -a "Firefox" book/index.html # OS X
$ Start-Process "firefox.exe" .\book\index.html # Windows (PowerShell)
$ start firefox.exe .\book\index.html # Windows (Cmd)
Chrome:
$ google-chrome book/index.html # Linux
$ open -a "Google Chrome" book/index.html # OS X
$ Start-Process "chrome.exe" .\book\index.html # Windows (PowerShell)
$ start chrome.exe .\book\index.html # Windows (Cmd)
To run the tests:
$ mdbook test
Contributing
We'd love your help! Please see CONTRIBUTING.md to learn about the kinds of contributions we're looking for.
Translations
We'd especially love help translating the second edition of the book! See the Translations label to join in efforts that are currently in progress. Open a new issue to start working on a new language! We're waiting on mdbook support for multiple languages before we merge any in, but feel free to start! The chapters in the frozen column of the project won't see major changes, so if you start with those, you won't have to redo work :)
No Starch
As the second edition of the book will be published by No Starch, we first iterate here, then ship the text off to No Starch. Then they do editing, and we fold it back in.
As such, there’s a directory, nostarch, which corresponds to the text in No Starch’s system.
When we've started working with No Starch in a word doc, we will also check those into the repo in the nostarch/odt directory. To extract the text from the word doc as markdown in order to backport changes to the online book:
- Open the doc file in LibreOffice
- Accept all tracked changes
- Save as Microsoft Word 2007-2013 XML (.docx) in the tmp directory
- Run
./doc-to-md.sh - Inspect changes made to the markdown file in the nostarch directory and copy the changes to the src directory as appropriate.
Graphviz dot
This is mostly for Carol's reference because she keeps having to look it up.
We're using Graphviz for some of the diagrams in the
book. The source for those files live in the dot directory. To turn a dot
file, for example, dot/trpl04-01.dot into an svg, run:
$ dot dot/trpl04-01.dot -Tsvg > src/img/trpl04-01.svg
In the generated SVG, remove the width and the height attributes from the svg
element and set the viewBox attribute to 0.00 0.00 1000.00 1000.00 or other
values that don't cut off the image.
Spellchecking
To scan source files for spelling errors, you can use the spellcheck.sh
script. It needs a dictionary of valid words, which is provided in
dictionary.txt. If the script produces a false positive (say, you used word
BTreeMap which the script considers invalid), you need to add this word to
dictionary.txt (keep the sorted order for consistency).