Skip to content

Commit

Permalink
Merge branch 'master' of github.com:rust-lang/book
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexis Hunt committed Mar 16, 2018
2 parents 5c2d0b7 + 76fa546 commit 567bc1d
Show file tree
Hide file tree
Showing 141 changed files with 11,089 additions and 12,271 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ addons:
- aspell
- aspell-en
before_script:
- (cargo install mdbook --vers 0.0.26 --force || true)
- (cargo install mdbook --vers 0.1.2 --force || true)
script:
- bash ci/build.sh
24 changes: 10 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# NOTICE ABOUT STATUS

The second edition of The Rust Programming Language is getting ever closer to being printed!
This means we're not able to make large changes to chapters that are in any column to the
This means we're not able to make large changes to chapters that are in any column to the
right of, and including, the "Frozen" column [on our Project board][proj]. Issues or pull
requests submitted for frozen chapters are welcome but will be closed until we start work
on a third edition. Thank you!
Expand All @@ -12,22 +12,18 @@ on a third edition. Thank you!

[![Build Status](https://travis-ci.org/rust-lang/book.svg?branch=master)](https://travis-ci.org/rust-lang/book)

This repo contains two editions of “The Rust Programming Language”.
This repo contains two editions of “The Rust Programming Language”; we
recommend starting with the second edition.

The second edition is a rewrite that will be printed by NoStarch Press,
available around October 2017.
The second edition is a rewrite that will be printed by No Starch Press,
available around May 2018. Check [the No Starch Page][nostarch] for the latest
information on the release date and how to order.

[You can read the very latest online][html]; 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.
[nostarch]: https://nostarch.com/rust

[html]: http://rust-lang.github.io/book/

Note that links to the standard library won't work in this version; this is intentional
so that links work with the book and API docs shipped with Rust installations for offline
reading. For a version of the book where these links do work, please see the book as shipped
with the latest [stable], [beta], or [nightly] Rust releases. Be aware that issues in those
versions may have been fixed in this repository already.
You can read the book for free online! Please see the book as shipped with the
latest [stable], [beta], or [nightly] Rust releases. Be aware that issues in
those versions may have been fixed in this repository already.

[stable]: https://doc.rust-lang.org/stable/book/second-edition/
[beta]: https://doc.rust-lang.org/beta/book/second-edition/
Expand Down
4 changes: 4 additions & 0 deletions first-edition/book.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
[book]
title = "The Rust Programming Language"
author = "The Rust Project Developers"

[output.html]
additional-css = ["src/theme/first-edition.css"]
16 changes: 11 additions & 5 deletions first-edition/src/const-and-static.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ reference stored in a static has a [`'static` lifetime][lifetimes]:
static NAME: &'static str = "Steve";
```

The type of a `static` value must be `Sync` unless the `static` value is
mutable.

[lifetimes]: lifetimes.html

## Mutability
Expand All @@ -64,17 +67,20 @@ unsafe {

[unsafe]: unsafe.html

Furthermore, any type stored in a `static` must be `Sync`, and must not have
a [`Drop`][drop] implementation.

[drop]: drop.html

# Initializing

Both `const` and `static` have requirements for giving them a value. They must
be given a value that’s a constant expression. In other words, you cannot use
the result of a function call or anything similarly complex or at runtime.

# Dropping

Types implementing [`Drop`][drop] are allowed in `const` and `static`
definitions. Constants are inlined where they are used and are dropped
accordingly. `static` values are not dropped.

[drop]: drop.html

# Which construct should I use?

Almost always, if you can choose between the two, choose `const`. It’s pretty
Expand Down
6 changes: 3 additions & 3 deletions first-edition/src/ffi.md
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ against `libc` and `libm` by default.
In C, functions can be 'variadic', meaning they accept a variable number of arguments. This can
be achieved in Rust by specifying `...` within the argument list of a foreign function declaration:

```no_run
```rust,no_run
extern {
fn foo(x: i32, ...);
}
Expand All @@ -584,7 +584,7 @@ fn main() {

Normal Rust functions can *not* be variadic:

```ignore
```rust,ignore
// This will not compile
fn foo(x: i32, ...) { }
Expand Down Expand Up @@ -750,7 +750,7 @@ extern "C" {
# fn main() {}
```

By including a private field and no constructor,
By including a private field and no constructor,
we create an opaque type that we can’t instantiate outside of this module.
An empty array is both zero-size and compatible with `#[repr(C)]`.
But because our `Foo` and `Bar` types are
Expand Down
4 changes: 2 additions & 2 deletions first-edition/src/procedural-macros.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ fn impl_hello_world(ast: &syn::DeriveInput) -> quote::Tokens {
}
}
} else {
//Nope. This is an Enum. We cannot handle these!
panic!("#[derive(HelloWorld)] is only defined for structs, not for enums!");
// Nope. This is an Enum. We cannot handle these!
panic!("#[derive(HelloWorld)] is only defined for structs, not for enums!");
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion first-edition/src/the-stack-and-the-heap.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ like this:
| 1 | y | 42 |
| 0 | x | → (2<sup>30</sup>) - 1 |

We have (2<sup>30</sup>) addresses in our hypothetical computer with 1GB of RAM. And since
We have (2<sup>30</sup>) addresses in our hypothetical computer with 1GiB of RAM. And since
our stack grows from zero, the easiest place to allocate memory is from the
other end. So our first value is at the highest place in memory. And the value
of the struct at `x` has a [raw pointer][rawpointer] to the place we’ve
Expand Down
56 changes: 56 additions & 0 deletions first-edition/src/theme/first-edition.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
.warning {
display: flex;
justify-content: space-between;
align-items: center;
background-color: rgb(242, 222, 222);
border-bottom-color: rgb(238, 211, 215);
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border-bottom-style: solid;
border-bottom-width: 0.666667px;
border-image-outset: 0 0 0 0;
border-image-repeat: stretch stretch;
border-image-slice: 100% 100% 100% 100%;
border-image-source: none;
border-image-width: 1 1 1 1;
border-left-color: rgb(238, 211, 215);
border-left-style: solid;
border-left-width: 0.666667px;
border-right-color: rgb(238, 211, 215);
border-right-style: solid;
border-right-width: 0.666667px;
border-top-color: rgb(238, 211, 215);
border-top-left-radius: 4px;
border-top-right-radius: 4px;
border-top-style: solid;
border-top-width: 0.666667px;
color: rgb(185, 74, 72);
margin-bottom: 0px;
margin-left: 0px;
margin-right: 0px;
margin-top: 30px;
padding-bottom: 8px;
padding-left: 14px;
padding-right: 35px;
padding-right: 14px;
padding-top: 8px;
}
.warning strong {
color: rgb(185, 74, 72)
}
.warning a {
color: rgb(0, 136, 204)
}
.warning .message {
margin-right: 14px;
}
.warning .message:last-child {
margin-right: 21px;
}
.warning .button {
border: none;
background: none;
color: inherit;
cursor: pointer;
font-size: 14px;
}
27 changes: 27 additions & 0 deletions first-edition/src/theme/header.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<div id="draft-warning" class="warning">
<span class="message">You are reading an <strong>outdated</strong> edition of TRPL. For more, go <a href="../index.html">here</a>.</span>
<button type="button" id="hide-draft-warning" title="Hide draft warning" class="button">
<i class="fa fa-times"></i>
</button>
</div>
<!-- Hide / unhide warning before it is displayed -->
<script type="text/javascript">
var warning = localStorage.getItem('trpl-first-edition-draft-warning');
if (warning === 'hidden') {
Array
.from(document.querySelectorAll('#page-wrapper'))
.forEach(function(block) { block.classList.remove('has-warning'); });
var elem = document.getElementById("draft-warning");
elem.parentNode.removeChild(elem);
}
document.addEventListener("DOMContentLoaded", function(event) {
document.getElementById("hide-draft-warning").addEventListener("click", function(e) {
var elem = document.getElementById("draft-warning");
elem.parentNode.removeChild(elem);
localStorage.setItem('trpl-first-edition-draft-warning', 'hidden');
});
});
</script>
30 changes: 22 additions & 8 deletions index.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
% The Rust Programming Language
# The Rust Programming Language

There are two editions of "The Rust Programming Language":
The current edition of "The Rust Programming Language" is the second
edition, which you can [read here](second-edition/index.html).

* [First edition](first-edition/index.html)
* [Second edition](second-edition/index.html)
The source for all editions lives [on GitHub](https://github.com/rust-lang/book).
Please open issues with any questions, concerns, or tweaks.

The second edition is a complete re-write. It is still under construction,
though it is far enough along to learn most of Rust. We suggest reading the
second edition and then checking out the first edition later to pick up some of
the more esoteric parts of the language.
## Notes

The second edition is still receiving some minor edits, but is effectively
complete. It will be [available in dead-tree form through NoStarch
Press](https://nostarch.com/Rust) once these final edits are complete.

The second edition is a complete re-write of TRPL, from the ground up,
and is therefore very different from the first edition.

## Other editions

We keep older editions of TRPL online for history's sake.

### First Edition

You can [read the first edition of "The Rust Programming Language"
here](first-edition/index.html).
2 changes: 1 addition & 1 deletion redirects/associated-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ Here are the relevant sections in the new and old books:


[1]: first-edition/associated-types.html
[2]: second-edition/ch19-03-advanced-traits.html#associated-types
[2]: second-edition/ch19-03-advanced-traits.html#associated-types-specify-placeholder-types-in-trait-definitions
4 changes: 2 additions & 2 deletions redirects/casting-between-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ fn average(values: &[f64]) -> f64 {

Here are the relevant sections in the new and old books:

* **[In the second edition: Appendix BOperators, section Type Cast Expressions][2]**
* **[In the second edition: Appendix AKeywords][2]**
* [In the Rust Reference: Type Cast Expressions][3]
* [In the Rust documentation: `mem::transmute`][4]
* <small>[In the first edition: Ch 3.29 — Casting between types][1]</small>


[1]: first-edition/casting-between-types.html
[2]: second-edition/appendix-02-operators.html#type-cast-expressions
[2]: second-edition/appendix-01-keywords.html
[3]: ../reference/expressions/operator-expr.html#type-cast-expressions
[4]: ../std/mem/fn.transmute.html
2 changes: 1 addition & 1 deletion redirects/closures.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let expensive_closure = |num| {
thread::sleep(Duration::from_secs(2));
num
};
#expensive_closure(5);
# expensive_closure(5);
```

---
Expand Down
3 changes: 0 additions & 3 deletions redirects/compiler-plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,5 @@
This particular chapter has moved to [the Unstable Book][2].

* **[In the Unstable Rust Book: `plugin`][2]**
* <small><del>[In the first edition: Compiler Plugins][1]</del> (does not exist anymore)</small>


[1]: first-edition/compiler-plugins.html
[2]: ../unstable-book/language-features/plugin.html
2 changes: 1 addition & 1 deletion redirects/conditional-compilation.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ The best place to learn about it is [the Rust Reference][3].


[1]: first-edition/conditional-compilation.html
[2]: second-edition/
[2]: second-edition/index.html
[3]: ../reference/attributes.html#conditional-compilation
2 changes: 1 addition & 1 deletion redirects/effective-rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ It is recommended to start there.


[1]: first-edition/effective-rust.html
[2]: second-edition/
[2]: second-edition/index.html
2 changes: 1 addition & 1 deletion redirects/ffi.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ Here are the relevant sections in the new and old books:


[1]: first-edition/ffi.html
[2]: second-edition/ch19-01-unsafe-rust.html#extern--functions-for-calling-external-code-are-unsafe
[2]: second-edition/ch19-01-unsafe-rust.html#using-extern-functions-to-call-external-code
4 changes: 2 additions & 2 deletions redirects/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
You can [continue to the exact older page][1].
If you're trying to learn Rust, checking out [the second edition][2] might be a better choice.

* **[In the second edition: Introduction][2]**
* **[In the second edition: Getting Started][2]**
* <small>[In the first edition: Getting Started][1]</small>


[1]: first-edition/getting-started.html
[2]: second-edition/ch01-00-introduction.html
[2]: second-edition/ch01-00-getting-started.html
2 changes: 1 addition & 1 deletion redirects/glossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ It is recommended to start there.


[1]: first-edition/glossary.html
[2]: second-edition/
[2]: second-edition/index.html
4 changes: 2 additions & 2 deletions redirects/macros.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ You can check out other resources that describe macros.

* **[Rust By Example: Macros][3]**
* [In the Rust Reference: Ch 3.1 — Macros by Example][4]
* [In the second edition: (future) Appendix E — Macros][2]
* [In the second edition: (future) Appendix D — Macros][2]
* <small>[In the first edition: Ch 3.34 — Macros][1]</small>


[1]: first-edition/macros.html
[2]: second-edition/appendix-05-macros.html
[2]: second-edition/appendix-04-macros.html
[3]: https://rustbyexample.com/macros.html
[4]: ../reference/macros-by-example.html
4 changes: 2 additions & 2 deletions redirects/operators-and-overloading.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ Here are the relevant sections in the new and old books:
* <small>[In the first edition: Ch 3.32 — Operators and Overloading][1]</small>

[1]: first-edition/operators-and-overloading.html
[2]: second-edition/ch19-03-advanced-traits.html#operator-overloading-and-default-type-parameters
[3]: ../std/ops/
[2]: second-edition/ch19-03-advanced-traits.html#default-generic-type-parameters-and-operator-overloading
[3]: ../std/ops/index.html
6 changes: 3 additions & 3 deletions redirects/procedural-macros.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ You can check out other resources that describe macros.

* **[In the Rust Reference: Ch 3.2 — Procedural Macros][4]**
* [The `proc_macro` crate documentation][3]
* [In the second edition: (future) Appendix E — Macros][2]
* [In the second edition: (future) Appendix D — Macros][2]
* <small>[In the first edition: Ch 4.13 — Procedural Macros (and custom Derive)][1]</small>


[1]: first-edition/procedural-macros.html
[2]: second-edition/appendix-05-macros.html
[3]: ../stable/proc_macro/index.html
[2]: second-edition/appendix-04-macros.html
[3]: ../proc_macro/index.html
[4]: ../reference/procedural-macros.html
4 changes: 2 additions & 2 deletions redirects/release-channels.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ You can check out other resources that describe release channels.
* **[In the Rustup documentation: Keeping Rust Up-to-date][4]**
* [On the website: Install Rust][5]
* [In the Rust RFCs: RFC 507 — Release Channels][3]
* [In the second edition: (future) Appendix D — Nightly Rust][2]
* [In the second edition: How Rust is Made and “Nightly Rust][2]
* <small>[In the first edition: Ch 4.11 — Release Channels][1]</small>


[1]: first-edition/release-channels.html
[2]: second-edition/appendix-04-nightly-rust.html
[2]: second-edition/appendix-07-nightly-rust.html
[3]: https://github.com/rust-lang/rfcs/blob/master/text/0507-release-channels.md
[4]: https://github.com/rust-lang-nursery/rustup.rs/blob/master/README.md#keeping-rust-up-to-date
[5]: https://www.rust-lang.org/en-US/install.html
Expand Down
2 changes: 1 addition & 1 deletion redirects/trait-objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
> A trait defines behavior that we need in a given situation.
> We can then use a trait as a trait object in places where we would use a concrete type or a generic type.
```rust
```rust,ignore
pub struct InputBox {
pub label: String,
}
Expand Down
Loading

0 comments on commit 567bc1d

Please sign in to comment.