Auto merge of #39633 - steveklabnik:vendor-mdbook, r=alexcrichton

Port books to mdbook

Part of https://github.com/rust-lang/rust/issues/39588

blocked on https://github.com/rust-lang/rust/pull/39431

As a first step towards the bookshelf, we ~vendor mdbook in-tree and~ port our books to it. Eventually, both of these books will be moved out-of-tree, but the nightly book will rely on doing the same thing. As such, this intermediate step is useful.

r? @alexcrichton @brson

/cc @azerupi
This commit is contained in:
bors 2017-02-15 01:22:16 +00:00
commit 025c328bf5
151 changed files with 587 additions and 1199 deletions

2
.gitattributes vendored
View File

@ -6,4 +6,4 @@
*.rs rust
src/etc/installer/gfx/* binary
*.woff binary
src/vendor/* binary
src/vendor/** -text

1
.gitignore vendored
View File

@ -100,3 +100,4 @@ version.md
version.ml
version.texi
.cargo
!src/vendor/**

216
src/Cargo.lock generated
View File

@ -6,6 +6,14 @@ dependencies = [
"libc 0.0.0",
]
[[package]]
name = "aho-corasick"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "alloc"
version = "0.0.0"
@ -31,10 +39,25 @@ dependencies = [
"libc 0.0.0",
]
[[package]]
name = "ansi_term"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "arena"
version = "0.0.0"
[[package]]
name = "bitflags"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "bitflags"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "bootstrap"
version = "0.0.0"
@ -69,6 +92,21 @@ dependencies = [
name = "cargotest"
version = "0.1.0"
[[package]]
name = "clap"
version = "2.19.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
"strsim 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"term_size 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-segmentation 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"vec_map 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "cmake"
version = "0.1.18"
@ -114,6 +152,7 @@ version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 0.1.80 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -158,6 +197,33 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
name = "graphviz"
version = "0.0.0"
[[package]]
name = "handlebars"
version = "0.20.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"pest 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"quick-error 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 0.1.80 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "kernel32-sys"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "lazy_static"
version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "libc"
version = "0.0.0"
@ -183,6 +249,27 @@ name = "log"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "mdbook"
version = "0.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"clap 2.19.3 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"handlebars 0.20.5 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"pulldown-cmark 0.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "memchr"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num_cpus"
version = "0.2.13"
@ -209,6 +296,11 @@ dependencies = [
"unwind 0.0.0",
]
[[package]]
name = "pest"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "proc_macro"
version = "0.0.0"
@ -225,6 +317,15 @@ dependencies = [
"syntax_pos 0.0.0",
]
[[package]]
name = "pulldown-cmark"
version = "0.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "qemu-test-client"
version = "0.1.0"
@ -233,6 +334,11 @@ version = "0.1.0"
name = "qemu-test-server"
version = "0.1.0"
[[package]]
name = "quick-error"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rand"
version = "0.0.0"
@ -240,9 +346,30 @@ dependencies = [
"core 0.0.0",
]
[[package]]
name = "regex"
version = "0.1.80"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"aho-corasick 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
"memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
"regex-syntax 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"thread_local 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
"utf8-ranges 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "regex-syntax"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rustbook"
version = "0.0.0"
version = "0.1.0"
dependencies = [
"clap 2.19.3 (registry+https://github.com/rust-lang/crates.io-index)",
"mdbook 0.0.14 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rustc"
@ -650,6 +777,11 @@ dependencies = [
"core 0.0.0",
]
[[package]]
name = "strsim"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "syntax"
version = "0.0.0"
@ -685,6 +817,16 @@ dependencies = [
name = "term"
version = "0.0.0"
[[package]]
name = "term_size"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "test"
version = "0.0.0"
@ -700,6 +842,23 @@ dependencies = [
"test 0.0.0",
]
[[package]]
name = "thread-id"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "thread_local"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"thread-id 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "tidy"
version = "0.1.0"
@ -712,14 +871,69 @@ dependencies = [
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "unicode-segmentation"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "unicode-width"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "utf8-ranges"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "vec_map"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi-build"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum aho-corasick 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ca972c2ea5f742bfce5687b9aef75506a764f61d37f8f649047846a9686ddb66"
"checksum ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "23ac7c30002a5accbf7e8987d0632fa6de155b7c3d39d0067317a391e00a2ef6"
"checksum bitflags 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4f67931368edf3a9a51d29886d245f1c3db2f1ef0dcc9e35ff70341b78c10d23"
"checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d"
"checksum clap 2.19.3 (registry+https://github.com/rust-lang/crates.io-index)" = "95b78f3fe0fc94c13c731714363260e04b557a637166f33a4570d3189d642374"
"checksum cmake 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)" = "0e5bcf27e097a184c1df4437654ed98df3d7a516e8508a6ba45d8b092bbdf283"
"checksum env_logger 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "15abd780e45b3ea4f76b4e9a26ff4843258dd8a3eed2775a0e7368c2e7936c2f"
"checksum filetime 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "5363ab8e4139b8568a6237db5248646e5a8a2f89bd5ccb02092182b11fd3e922"
"checksum gcc 0.3.43 (registry+https://github.com/rust-lang/crates.io-index)" = "c07c758b972368e703a562686adb39125707cc1ef3399da8c019fc6c2498a75d"
"checksum getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9047cfbd08a437050b363d35ef160452c5fe8ea5187ae0a624708c91581d685"
"checksum handlebars 0.20.5 (registry+https://github.com/rust-lang/crates.io-index)" = "07f9c1d28bcfb97143c95ed0667141677b2b5675c7ba3d5b81459ad43b1073bd"
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
"checksum lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "cf186d1a8aa5f5bee5fd662bc9c1b949e0259e1bcc379d1f006847b0080c7417"
"checksum libc 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)" = "044d1360593a78f5c8e5e710beccdc24ab71d1f01bc19a29bcacdba22e8475d8"
"checksum log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ab83497bf8bf4ed2a74259c1c802351fcd67a65baa86394b6ba73c36f4838054"
"checksum mdbook 0.0.14 (registry+https://github.com/rust-lang/crates.io-index)" = "a629cd0194bbd0340a70db83a94b27cf9881fac8c55e6a2db983addcb7114ee4"
"checksum memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d8b629fb514376c675b98c1421e80b151d3817ac42d7c667717d282761418d20"
"checksum num_cpus 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "cee7e88156f3f9e19bdd598f8d6c9db7bf4078f99f8381f43a55b09648d1a6e3"
"checksum pest 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0a6dda33d67c26f0aac90d324ab2eb7239c819fc7b2552fe9faa4fe88441edc8"
"checksum pulldown-cmark 0.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "1058d7bb927ca067656537eec4e02c2b4b70eaaa129664c5b90c111e20326f41"
"checksum quick-error 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0aad603e8d7fb67da22dbdf1f4b826ce8829e406124109e73cf1b2454b93a71c"
"checksum regex 0.1.80 (registry+https://github.com/rust-lang/crates.io-index)" = "4fd4ace6a8cf7860714a2c2280d6c1f7e6a413486c13298bbc86fd3da019402f"
"checksum regex-syntax 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "f9ec002c35e86791825ed294b50008eea9ddfc8def4420124fbc6b08db834957"
"checksum rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)" = "6159e4e6e559c81bd706afe9c8fd68f547d3e851ce12e76b1de7914bab61691b"
"checksum strsim 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "67f84c44fbb2f91db7fef94554e6b2ac05909c9c0b0bc23bb98d3a1aebfe7f7c"
"checksum term_size 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3f7f5f3f71b0040cecc71af239414c23fd3c73570f5ff54cf50e03cef637f2a0"
"checksum thread-id 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a9539db560102d1cef46b8b78ce737ff0bb64e7e18d35b2a5688f7d097d0ff03"
"checksum thread_local 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "8576dbbfcaef9641452d5cf0df9b0e7eeab7694956dd33bb61515fb8f18cfdd5"
"checksum toml 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)" = "0590d72182e50e879c4da3b11c6488dae18fccb1ae0c7a3eda18e16795844796"
"checksum unicode-segmentation 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c3bc443ded17b11305ffffe6b37e2076f328a5a8cb6aa877b1b98f77699e98b5"
"checksum unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3a113775714a22dcb774d8ea3655c53a32debae63a063acc00a91cc586245f"
"checksum utf8-ranges 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a1ca13c08c41c9c3e04224ed9ff80461d97e121589ff27c753a16cb10830ae0f"
"checksum vec_map 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cac5efe5cb0fa14ec2f84f83c701c562ee63f6dcc680861b21d65c682adfb05f"
"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"

View File

@ -47,6 +47,7 @@ pub fn rustbook(build: &Build, target: &str, name: &str) {
build.run(build.tool_cmd(&compiler, "rustbook")
.arg("build")
.arg(&src)
.arg("-d")
.arg(out));
}

View File

@ -1,4 +1,4 @@
% The Rust Programming Language
# The Rust Programming Language
Welcome! This book will teach you about the [Rust Programming Language][rust].
Rust is a systems programming language focused on three goals: safety, speed,

View File

@ -1,5 +1,7 @@
# Summary
[Introduction](README.md)
* [Getting Started](getting-started.md)
* [Tutorial: Guessing Game](guessing-game.md)
* [Syntax and Semantics](syntax-and-semantics.md)

View File

@ -1,4 +1,4 @@
% Advanced Linking
# Advanced Linking
The common cases of linking with Rust have been covered earlier in this book,
but supporting the range of linking possibilities made available by other

View File

@ -1,4 +1,4 @@
% Associated Constants
# Associated Constants
With the `associated_consts` feature, you can define constants like this:

View File

@ -1,4 +1,4 @@
% Associated Types
# Associated Types
Associated types are a powerful part of Rusts type system. Theyre related to
the idea of a type family, in other words, grouping multiple types together. That

View File

@ -1,4 +1,4 @@
% Attributes
# Attributes
Declarations can be annotated with attributes in Rust. They look like this:

View File

@ -1,4 +1,4 @@
% Benchmark tests
# Benchmark tests
Rust supports benchmark tests, which can test the performance of your
code. Let's make our `src/lib.rs` look like this (comments elided):

View File

@ -1,4 +1,4 @@
% Bibliography
# Bibliography
This is a reading list of material relevant to Rust. It includes prior
research that has - at one time or another - influenced the design of

View File

@ -1,4 +1,4 @@
% Borrow and AsRef
# Borrow and AsRef
The [`Borrow`][borrow] and [`AsRef`][asref] traits are very similar, but
different. Heres a quick refresher on what these two traits mean.

View File

@ -1,4 +1,4 @@
% Box Syntax and Patterns
# Box Syntax and Patterns
Currently the only stable way to create a `Box` is via the `Box::new` method.
Also it is not possible in stable Rust to destructure a `Box` in a match

View File

@ -1,4 +1,4 @@
% Casting Between Types
# Casting Between Types
Rust, with its focus on safety, provides two different ways of casting
different types between each other. The first, `as`, is for safe casts.
@ -8,7 +8,7 @@ most dangerous features of Rust!
# Coercion
Coercion between types is implicit and has no syntax of its own, but can
be spelled out with [`as`](#explicit-coercions).
be spelled out with [`as`](#Explicit%20coercions).
Coercion occurs in `let`, `const`, and `static` statements; in
function call arguments; in field values in struct initialization; and in a
@ -19,7 +19,7 @@ The most common case of coercion is removing mutability from a reference:
* `&mut T` to `&T`
An analogous conversion is to remove mutability from a
[raw pointer](raw-pointers.md):
[raw pointer](raw-pointers.html):
* `*mut T` to `*const T`
@ -29,7 +29,7 @@ References can also be coerced to raw pointers:
* `&mut T` to `*mut T`
Custom coercions may be defined using [`Deref`](deref-coercions.md).
Custom coercions may be defined using [`Deref`](deref-coercions.html).
Coercion is transitive.
@ -101,7 +101,7 @@ The semantics of numeric casts are:
## Pointer casts
Perhaps surprisingly, it is safe to cast [raw pointers](raw-pointers.md) to and
Perhaps surprisingly, it is safe to cast [raw pointers](raw-pointers.html) to and
from integers, and to cast between pointers to different types subject to
some constraints. It is only unsafe to dereference the pointer:

View File

@ -0,0 +1 @@
# Chapter 1

View File

@ -1,4 +1,4 @@
% Choosing your Guarantees
# Choosing your Guarantees
One important feature of Rust is that it lets us control the costs and guarantees
of a program.

View File

@ -1,4 +1,4 @@
% Closures
# Closures
Sometimes it is useful to wrap up a function and _free variables_ for better
clarity and reuse. The free variables that can be used come from the
@ -463,7 +463,7 @@ fn factory() -> &(Fn(i32) -> i32) {
Right. Because we have a reference, we need to give it a lifetime. But
our `factory()` function takes no arguments, so
[elision](lifetimes.html#lifetime-elision) doesnt kick in here. Then what
[elision](lifetimes.html#Lifetime%20Elision) doesnt kick in here. Then what
choices do we have? Try `'static`:
```rust,ignore

View File

@ -1,4 +1,4 @@
% Comments
# Comments
Now that we have some functions, its a good idea to learn about comments.
Comments are notes that you leave to other programmers to help explain things

View File

@ -1,6 +1,6 @@
% Compiler Plugins
# Compiler Plugins
# Introduction
## Introduction
`rustc` can load compiler plugins, which are user-provided libraries that
extend the compiler's behavior with new syntax extensions, lint checks, etc.
@ -127,7 +127,7 @@ enum. For a more involved macro example, see
## Tips and tricks
Some of the [macro debugging tips](macros.html#debugging-macro-code) are applicable.
Some of the [macro debugging tips](macros.html#Debugging%20macro%20code) are applicable.
You can use `syntax::parse` to turn token trees into
higher-level syntax elements like expressions:

View File

@ -1,4 +1,4 @@
% Concurrency
# Concurrency
Concurrency and parallelism are incredibly important topics in computer
science, and are also a hot topic in industry today. Computers are gaining more
@ -55,7 +55,7 @@ For sharing references across threads, Rust provides a wrapper type called
`Arc<T>`. `Arc<T>` implements `Send` and `Sync` if and only if `T` implements
both `Send` and `Sync`. For example, an object of type `Arc<RefCell<U>>` cannot
be transferred across threads because
[`RefCell`](choosing-your-guarantees.html#refcellt) does not implement
[`RefCell`](choosing-your-guarantees.html#RefCell%3CT%3E) does not implement
`Sync`, consequently `Arc<RefCell<U>>` would not implement `Send`.
These two traits allow you to use the type system to make strong guarantees
@ -126,7 +126,7 @@ closure only captures a _reference to `x`_. This is a problem, because the
thread may outlive the scope of `x`, leading to a dangling pointer.
To fix this, we use a `move` closure as mentioned in the error message. `move`
closures are explained in depth [here](closures.html#move-closures); basically
closures are explained in depth [here](closures.html#move%20closures); basically
they move variables from their environment into themselves.
```rust

View File

@ -1,4 +1,4 @@
% Conditional Compilation
# Conditional Compilation
Rust has a special attribute, `#[cfg]`, which allows you to compile code
based on a flag passed to the compiler. It has two forms:

View File

@ -1,4 +1,4 @@
% const and static
# const and static
Rust has a way of defining constants with the `const` keyword:

View File

@ -1,4 +1,4 @@
% Crates and Modules
# Crates and Modules
When a project starts getting large, its considered good software
engineering practice to split it up into a bunch of smaller pieces, and then

View File

@ -1,4 +1,4 @@
% Custom Allocators
# Custom Allocators
Allocating memory isn't always the easiest thing to do, and while Rust generally
takes care of this by default it often becomes necessary to customize how

View File

@ -1,4 +1,4 @@
% `Deref` coercions
# `Deref` coercions
The standard library provides a special trait, [`Deref`][deref]. Its normally
used to overload `*`, the dereference operator:

View File

@ -1,4 +1,4 @@
% Documentation
# Documentation
Documentation is an important part of any software project, and it's
first-class in Rust. Let's talk about the tooling Rust gives you to

View File

@ -1,4 +1,4 @@
% Drop
# Drop
Now that weve discussed traits, lets talk about a particular trait provided
by the Rust standard library, [`Drop`][drop]. The `Drop` trait provides a way

View File

@ -1,4 +1,4 @@
% Effective Rust
# Effective Rust
So youve learned how to write some Rust code. But theres a difference between
writing *any* Rust code and writing *good* Rust code.

View File

@ -1,4 +1,4 @@
% Enums
# Enums
An `enum` in Rust is a type that represents data that is one of
several possible variants. Each variant in the `enum` can optionally

View File

@ -1,4 +1,4 @@
% Error Handling
# Error Handling
Like most programming languages, Rust encourages the programmer to handle
errors in a particular way. Generally speaking, error handling is divided into
@ -21,35 +21,35 @@ sum types and combinators, and try to motivate the way Rust does error handling
incrementally. As such, programmers with experience in other expressive type
systems may want to jump around.
* [The Basics](#the-basics)
* [Unwrapping explained](#unwrapping-explained)
* [The `Option` type](#the-option-type)
* [Composing `Option<T>` values](#composing-optiont-values)
* [The `Result` type](#the-result-type)
* [Parsing integers](#parsing-integers)
* [The `Result` type alias idiom](#the-result-type-alias-idiom)
* [A brief interlude: unwrapping isn't evil](#a-brief-interlude-unwrapping-isnt-evil)
* [Working with multiple error types](#working-with-multiple-error-types)
* [Composing `Option` and `Result`](#composing-option-and-result)
* [The limits of combinators](#the-limits-of-combinators)
* [Early returns](#early-returns)
* [The `try!` macro](#the-try-macro)
* [Defining your own error type](#defining-your-own-error-type)
* [Standard library traits used for error handling](#standard-library-traits-used-for-error-handling)
* [The `Error` trait](#the-error-trait)
* [The `From` trait](#the-from-trait)
* [The real `try!` macro](#the-real-try-macro)
* [Composing custom error types](#composing-custom-error-types)
* [Advice for library writers](#advice-for-library-writers)
* [Case study: A program to read population data](#case-study-a-program-to-read-population-data)
* [Initial setup](#initial-setup)
* [Argument parsing](#argument-parsing)
* [Writing the logic](#writing-the-logic)
* [Error handling with `Box<Error>`](#error-handling-with-boxerror)
* [Reading from stdin](#reading-from-stdin)
* [Error handling with a custom type](#error-handling-with-a-custom-type)
* [Adding functionality](#adding-functionality)
* [The short story](#the-short-story)
* [The Basics](#The%20Basics)
* [Unwrapping explained](#Unwrapping%20explained)
* [The `Option` type](#The%20Option%20type)
* [Composing `Option<T>` values](#Composing%20Option%3CT%3E%20values)
* [The `Result` type](#The%20Result%20type)
* [Parsing integers](#Parsing%20integers)
* [The `Result` type alias idiom](#The%20Result%20type%20alias%20idiom)
* [A brief interlude: unwrapping isn't evil](#A%20brief%20interlude:%20unwrapping%20isnt%20evil)
* [Working with multiple error types](#Working%20with%20multiple%20error%20types)
* [Composing `Option` and `Result`](#Composing%20Option%20and%20Result)
* [The limits of combinators](#The%20limits%20of%20combinators)
* [Early returns](#Early%20returns)
* [The `try!` macro](#The%20try%20macro)
* [Defining your own error type](#Defining%20your%20own%20error%20type)
* [Standard library traits used for error handling](#Standard%20library%20traits%20used%20for%20error%20handling)
* [The `Error` trait](#The%20Error%20trait)
* [The `From` trait](#The%20From%20trait)
* [The real `try!` macro](#The%20real%20try%20macro)
* [Composing custom error types](#Composing%20custom%20error%20types)
* [Advice for library writers](#Advice%20for%20library%20writers)
* [Case study: A program to read population data](#Case%20study:%20A%20program%20to%20read%20population%20data)
* [Initial setup](#Initial%20setup)
* [Argument parsing](#Argument%20parsing)
* [Writing the logic](#Writing%20the%20logic)
* [Error handling with `Box<Error>`](#Error%20handling%20with%20Box%3CError%3E)
* [Reading from stdin](#Reading%20from%20stdin)
* [Error handling with a custom type](#Error%20handling%20with%20a%20custom%20type)
* [Adding functionality](#Adding%20functionality)
* [The short story](#The%20short%20story)
# The Basics
@ -796,7 +796,7 @@ because of the return types of
[`std::fs::File::open`](../std/fs/struct.File.html#method.open) and
[`std::io::Read::read_to_string`](../std/io/trait.Read.html#method.read_to_string).
(Note that they both use the [`Result` type alias
idiom](#the-result-type-alias-idiom) described previously. If you
idiom](#The%20Result%20type%20alias%20idiom) described previously. If you
click on the `Result` type, you'll [see the type
alias](../std/io/type.Result.html), and consequently, the underlying
`io::Error` type.) The third problem is described by the
@ -1120,7 +1120,7 @@ returns an `&Error`, which is itself a trait object. We'll revisit the
For now, it suffices to show an example implementing the `Error` trait. Let's
use the error type we defined in the
[previous section](#defining-your-own-error-type):
[previous section](#Defining%20your%20own%20error%20type):
```rust
use std::io;
@ -1493,19 +1493,19 @@ representation. But certainly, this will vary depending on use cases.
At a minimum, you should probably implement the
[`Error`](../std/error/trait.Error.html)
trait. This will give users of your library some minimum flexibility for
[composing errors](#the-real-try-macro). Implementing the `Error` trait also
[composing errors](#The%20real%20try%20macro). Implementing the `Error` trait also
means that users are guaranteed the ability to obtain a string representation
of an error (because it requires impls for both `fmt::Debug` and
`fmt::Display`).
Beyond that, it can also be useful to provide implementations of `From` on your
error types. This allows you (the library author) and your users to
[compose more detailed errors](#composing-custom-error-types). For example,
[compose more detailed errors](#Composing%20custom%20error%20types). For example,
[`csv::Error`](http://burntsushi.net/rustdoc/csv/enum.Error.html)
provides `From` impls for both `io::Error` and `byteorder::Error`.
Finally, depending on your tastes, you may also want to define a
[`Result` type alias](#the-result-type-alias-idiom), particularly if your
[`Result` type alias](#The%20Result%20type%20alias%20idiom), particularly if your
library defines a single error type. This is used in the standard library
for [`io::Result`](../std/io/type.Result.html)
and [`fmt::Result`](../std/fmt/type.Result.html).
@ -1538,7 +1538,7 @@ and [`rustc-serialize`](https://crates.io/crates/rustc-serialize) crates.
We're not going to spend a lot of time on setting up a project with
Cargo because it is already covered well in [the Cargo
section](getting-started.html#hello-cargo) and [Cargo's documentation][14].
section](getting-started.html#Hello%20Cargo) and [Cargo's documentation][14].
To get started from scratch, run `cargo new --bin city-pop` and make sure your
`Cargo.toml` looks something like this:
@ -1729,7 +1729,7 @@ error types and you don't need any `From` implementations. The downside is that
since `Box<Error>` is a trait object, it *erases the type*, which means the
compiler can no longer reason about its underlying type.
[Previously](#the-limits-of-combinators) we started refactoring our code by
[Previously](#The%20limits%20of%20combinators) we started refactoring our code by
changing the type of our function from `T` to `Result<T, OurErrorType>`. In
this case, `OurErrorType` is only `Box<Error>`. But what's `T`? And can we add
a return type to `main`?

View File

@ -1,4 +1,4 @@
% Foreign Function Interface
# Foreign Function Interface
# Introduction
@ -680,7 +680,7 @@ pub extern fn hello_rust() -> *const u8 {
The `extern` makes this function adhere to the C calling convention, as
discussed above in "[Foreign Calling
Conventions](ffi.html#foreign-calling-conventions)". The `no_mangle`
Conventions](ffi.html#Foreign%20calling%20conventions)". The `no_mangle`
attribute turns off Rust's name mangling, so that it is easier to link to.
# FFI and panics

View File

@ -1,4 +1,4 @@
% Functions
# Functions
Every Rust program has at least one function, the `main` function:

View File

@ -1,4 +1,4 @@
% Generics
# Generics
Sometimes, when writing a function or data type, we may want it to work for
multiple types of arguments. In Rust, we can do this with generics.

View File

@ -1,4 +1,4 @@
% Getting Started
# Getting Started
This first chapter of the book will get us going with Rust and its tooling.
First, well install Rust. Then, the classic Hello World program. Finally,
@ -236,7 +236,7 @@ language]*, which means that most things are expressions, rather than
statements. The `;` indicates that this expression is over, and the next one is
ready to begin. Most lines of Rust code end with a `;`.
[expression-oriented language]: glossary.html#expression-oriented-language
[expression-oriented language]: glossary.html#Expression-Oriented%20Language
## Compiling and Running Are Separate Steps

View File

@ -1,4 +1,4 @@
% Glossary
# Glossary
Not every Rustacean has a background in systems programming, nor in computer
science, so we've added explanations of terms that might be unfamiliar.
@ -56,7 +56,7 @@ They can be used to manage control flow in a modular fashion.
A type without a statically known size or alignment. ([more info][link])
[link]: ../nomicon/exotic-sizes.html#dynamically-sized-types-dsts
[link]: ../nomicon/exotic-sizes.html#Dynamically%20Sized%20Types%20(DSTs)
### Expression
@ -76,8 +76,8 @@ In an expression-oriented language, (nearly) every statement is an expression
and therefore returns a value. Consequently, these expression statements can
themselves form part of larger expressions.
[expression]: glossary.html#expression
[statement]: glossary.html#statement
[expression]: glossary.html#Expression
[statement]: glossary.html#Statement
### Statement

View File

@ -1,4 +1,4 @@
% Guessing Game
# Guessing Game
Lets learn some Rust! For our first project, well implement a classic
beginner programming problem: the guessing game. Heres how it works: Our
@ -119,7 +119,7 @@ there are no arguments, and `{` starts the body of the function. Because
we didnt include a return type, its assumed to be `()`, an empty
[tuple][tuples].
[tuples]: primitive-types.html#tuples
[tuples]: primitive-types.html#Tuples
```rust,ignore
println!("Guess the number!");
@ -727,7 +727,7 @@ thirty-two bit integer. Rust has [a number of built-in number types][number],
but weve chosen `u32`. Its a good default choice for a small positive number.
[parse]: ../std/primitive.str.html#method.parse
[number]: primitive-types.html#numeric-types
[number]: primitive-types.html#Numeric%20types
Just like `read_line()`, our call to `parse()` could cause an error. What if
our string contained `A👍%`? Thered be no way to convert that to a number. As

View File

@ -1,4 +1,4 @@
% if let
# if let
`if let` permits [patterns][pattern] matching within the condition of an [if][if] statement.
This allows us to reduce the overhead of certain kinds of [pattern][patterns] matches

View File

@ -1,4 +1,4 @@
% if
# if
Rusts take on `if` is not particularly complex, but its much more like the
`if` youll find in a dynamically typed language than in a more traditional

View File

@ -1,4 +1,4 @@
% Inline Assembly
# Inline Assembly
For extremely low-level manipulations and performance reasons, one
might wish to control the CPU directly. Rust supports using inline

View File

@ -1,4 +1,4 @@
% Intrinsics
# Intrinsics
> **Note**: intrinsics will forever have an unstable interface, it is
> recommended to use the stable interfaces of libcore rather than intrinsics

View File

@ -1,4 +1,4 @@
% Iterators
# Iterators
Let's talk about loops.

View File

@ -1,4 +1,4 @@
% Lang items
# Lang items
> **Note**: lang items are often provided by crates in the Rust distribution,
> and lang items themselves have an unstable interface. It is recommended to use

View File

@ -1,4 +1,4 @@
% Lifetimes
# Lifetimes
This is the last of three sections presenting Rusts ownership system. This is one of
Rusts most distinct and compelling features, with which Rust developers should
@ -139,7 +139,7 @@ associated with it, but the compiler lets you elide (i.e. omit, see
["Lifetime Elision"][lifetime-elision] below) them in common cases. Before we
get to that, though, lets look at a short example with explicit lifetimes:
[lifetime-elision]: #lifetime-elision
[lifetime-elision]: #Lifetime%20Elision
```rust,ignore
fn bar<'a>(...)

View File

@ -1,4 +1,4 @@
% Loops
# Loops
Rust currently provides three approaches to performing some kind of iterative activity. They are: `loop`, `while` and `for`. Each approach has its own set of uses.

View File

@ -1,4 +1,4 @@
% Macros
# Macros
By now youve learned about many of the tools Rust provides for abstracting and
reusing code. These units of code reuse have a rich semantic structure. For
@ -432,7 +432,7 @@ Even when Rust code contains un-expanded macros, it can be parsed as a full
tools that process code. It also has a few consequences for the design of
Rusts macro system.
[ast]: glossary.html#abstract-syntax-tree
[ast]: glossary.html#Abstract%20Syntax%20Tree
One consequence is that Rust must determine, when it parses a macro invocation,
whether the macro stands in for

View File

@ -1,4 +1,4 @@
% Match
# Match
Often, a simple [`if`][if]/`else` isnt enough, because you have more than two
possible options. Also, conditions can get quite complex. Rust

View File

@ -1,4 +1,4 @@
% Method Syntax
# Method Syntax
Functions are great, but if you want to call a bunch of them on some data, it
can be awkward. Consider this code:

View File

@ -1,4 +1,4 @@
% Mutability
# Mutability
Mutability, the ability to change something, works a bit differently in Rust
than in other languages. The first aspect of mutability is its non-default
@ -89,7 +89,7 @@ philosophy, memory safety, and the mechanism by which Rust guarantees it, the
> * exactly one mutable reference (`&mut T`).
[ownership]: ownership.html
[borrowing]: references-and-borrowing.html#borrowing
[borrowing]: references-and-borrowing.html#Borrowing
So, thats the real definition of immutability: is this safe to have two
pointers to? In `Arc<T>`s case, yes: the mutation is entirely contained inside

View File

@ -1,8 +1,8 @@
% Nightly Rust
# Nightly Rust
Rust provides three distribution channels for Rust: nightly, beta, and stable.
Unstable features are only available on nightly Rust. For more details on this
process, see [Stability as a deliverable][stability].
process, see [Stability as a deliverable][stability].
[stability]: http://blog.rust-lang.org/2014/10/30/Stability.html
@ -91,9 +91,10 @@ If not, there are a number of places where you can get help. The easiest is
[the #rust IRC channel on irc.mozilla.org][irc], which you can access through
[Mibbit][mibbit]. Click that link, and you'll be chatting with other Rustaceans
(a silly nickname we call ourselves), and we can help you out. Other great
resources include [the users forum][users], and [Stack Overflow][stackoverflow].
resources include [the users forum][users], and [Stack Overflow][stackoverflow].
[irc]: irc://irc.mozilla.org/#rust
[mibbit]: http://chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust
[users]: https://users.rust-lang.org/
[stackoverflow]: http://stackoverflow.com/questions/tagged/rust

View File

@ -1,4 +1,4 @@
% No stdlib
# No stdlib
Rusts standard library provides a lot of useful functionality, but assumes
support for various features of its host system: threads, networking, heap

View File

@ -1,4 +1,4 @@
% Operators and Overloading
# Operators and Overloading
Rust allows for a limited form of operator overloading. There are certain
operators that are able to be overloaded. To support a particular operator

View File

@ -1,4 +1,4 @@
% Ownership
# Ownership
This is the first of three sections presenting Rusts ownership system. This is one of
Rusts most distinct and compelling features, with which Rust developers should
@ -65,10 +65,10 @@ elements onto them.
Vectors have a [generic type][generics] `Vec<T>`, so in this example `v` will have type
`Vec<i32>`. We'll cover [generics] in detail in a later chapter.
[arrays]: primitive-types.html#arrays
[arrays]: primitive-types.html#Arrays
[vectors]: vectors.html
[heap]: the-stack-and-the-heap.html#the-heap
[stack]: the-stack-and-the-heap.html#the-stack
[heap]: the-stack-and-the-heap.html#The%20Heap
[stack]: the-stack-and-the-heap.html#The%20Stack
[bindings]: variable-bindings.html
[generics]: generics.html
@ -136,7 +136,7 @@ Rust allocates memory for an integer [i32] on the [stack][sh], copies the bit
pattern representing the value of 10 to the allocated memory and binds the
variable name x to this memory region for future reference.
[i32]: primitive-types.html#numeric-types
[i32]: primitive-types.html#Numeric%20types
Now consider the following code fragment:

View File

@ -1,4 +1,4 @@
% Patterns
# Patterns
Patterns are quite common in Rust. We use them in [variable
bindings][bindings], [match expressions][match], and other places, too. Lets go

View File

@ -1,4 +1,4 @@
% Primitive Types
# Primitive Types
The Rust language has a number of types that are considered primitive. This
means that theyre built-in to the language. Rust is structured in such a way
@ -232,7 +232,7 @@ soon.
You can assign one tuple into another, if they have the same contained types
and [arity]. Tuples have the same arity when they have the same length.
[arity]: glossary.html#arity
[arity]: glossary.html#Arity
```rust
let mut x = (1, 2); // x: (i32, i32)

View File

@ -1,4 +1,4 @@
% Procedural Macros (and custom Derive)
# Procedural Macros (and custom Derive)
As you've seen throughout the rest of the book, Rust provides a mechanism
called "derive" that lets you implement traits easily. For example,

View File

@ -1,4 +1,4 @@
% Raw Pointers
# Raw Pointers
Rust has a number of different smart pointer types in its standard library, but
there are two types that are extra-special. Much of Rusts safety comes from

View File

@ -1,4 +1,4 @@
% References and Borrowing
# References and Borrowing
This is the second of three sections presenting Rusts ownership system. This is one of
Rusts most distinct and compelling features, with which Rust developers should

View File

@ -1,4 +1,4 @@
% Release Channels
# Release Channels
The Rust project uses a concept called release channels to manage releases.
Its important to understand this process to choose which version of Rust

View File

@ -1,4 +1,4 @@
% Slice patterns
# Slice patterns
If you want to match against a slice or array, you can use `&` with the
`slice_patterns` feature:

View File

@ -1,4 +1,4 @@
% Strings
# Strings
Strings are an important concept for any programmer to master. Rusts string
handling system is a bit different from other languages, due to its systems

View File

@ -1,4 +1,4 @@
% Structs
# Structs
`struct`s are a way of creating more complex data types. For example, if we were
doing calculations involving coordinates in 2D space, we would need both an `x`

View File

@ -1,4 +1,4 @@
% Syntax and Semantics
# Syntax and Semantics
This chapter breaks Rust down into small chunks, one for each concept.

View File

@ -1,4 +1,4 @@
% Syntax Index
# Syntax Index
## Keywords
@ -196,18 +196,18 @@
[Associated Types]: associated-types.html
[Attributes]: attributes.html
[Casting Between Types (`as`)]: casting-between-types.html#as
[Closures (`move` closures)]: closures.html#move-closures
[Closures (`move` closures)]: closures.html#move%20closures
[Closures]: closures.html
[Comments]: comments.html
[Crates and Modules (Defining Modules)]: crates-and-modules.html#defining-modules
[Crates and Modules (Exporting a Public Interface)]: crates-and-modules.html#exporting-a-public-interface
[Crates and Modules (Importing External Crates)]: crates-and-modules.html#importing-external-crates
[Crates and Modules (Importing Modules with `use`)]: crates-and-modules.html#importing-modules-with-use
[Crates and Modules (Re-exporting with `pub use`)]: crates-and-modules.html#re-exporting-with-pub-use
[Diverging Functions]: functions.html#diverging-functions
[Crates and Modules (Defining Modules)]: crates-and-modules.html#Defining%20modules
[Crates and Modules (Exporting a Public Interface)]: crates-and-modules.html#Exporting%20a%20public%20interface
[Crates and Modules (Importing External Crates)]: crates-and-modules.html#Importing%20external%20crates
[Crates and Modules (Importing Modules with `use`)]: crates-and-modules.html#Importing%20modules%20with%20use
[Crates and Modules (Re-exporting with `pub use`)]: crates-and-modules.html#Re-exporting%20with%20pub%20use
[Diverging Functions]: functions.html#Diverging%20functions
[Enums]: enums.html
[Foreign Function Interface]: ffi.html
[Functions (Early Returns)]: functions.html#early-returns
[Functions (Early Returns)]: functions.html#Early%20returns
[Functions]: functions.html
[Generics]: generics.html
[Iterators]: iterators.html
@ -216,24 +216,24 @@
[Loops (`for`)]: loops.html#for
[Loops (`loop`)]: loops.html#loop
[Loops (`while`)]: loops.html#while
[Loops (Ending Iteration Early)]: loops.html#ending-iteration-early
[Loops (Loops Labels)]: loops.html#loop-labels
[Loops (Ending Iteration Early)]: loops.html#Ending%20iteration%20early
[Loops (Loops Labels)]: loops.html#Loop%20labels
[Macros]: macros.html
[Match]: match.html
[Method Syntax (Method Calls)]: method-syntax.html#method-calls
[Method Syntax (Method Calls)]: method-syntax.html#Method%20calls
[Method Syntax]: method-syntax.html
[Mutability]: mutability.html
[Operators and Overloading]: operators-and-overloading.html
[Patterns (`ref` and `ref mut`)]: patterns.html#ref-and-ref-mut
[Patterns (Bindings)]: patterns.html#bindings
[Patterns (Ignoring bindings)]: patterns.html#ignoring-bindings
[Patterns (Multiple patterns)]: patterns.html#multiple-patterns
[Patterns (Ranges)]: patterns.html#ranges
[Patterns (`ref` and `ref mut`)]: patterns.html#ref%20and%20ref%20mut
[Patterns (Bindings)]: patterns.html#Bindings
[Patterns (Ignoring bindings)]: patterns.html#Ignoring%20bindings
[Patterns (Multiple patterns)]: patterns.html#Multiple%20patterns
[Patterns (Ranges)]: patterns.html#Ranges
[Primitive Types (`char`)]: primitive-types.html#char
[Primitive Types (Arrays)]: primitive-types.html#arrays
[Primitive Types (Booleans)]: primitive-types.html#booleans
[Primitive Types (Tuple Indexing)]: primitive-types.html#tuple-indexing
[Primitive Types (Tuples)]: primitive-types.html#tuples
[Primitive Types (Arrays)]: primitive-types.html#Arrays
[Primitive Types (Booleans)]: primitive-types.html#Booleans
[Primitive Types (Tuple Indexing)]: primitive-types.html#Tuple%20indexing
[Primitive Types (Tuples)]: primitive-types.html#Tuples
[Raw Pointers]: raw-pointers.html
[Reference (Byte String Literals)]: ../reference.html#byte-string-literals
[Reference (Integer literals)]: ../reference.html#integer-literals
@ -241,13 +241,13 @@
[Reference (Raw String Literals)]: ../reference.html#raw-string-literals
[References and Borrowing]: references-and-borrowing.html
[Strings]: strings.html
[Structs (Update syntax)]: structs.html#update-syntax
[Structs (Update syntax)]: structs.html#Update%20syntax
[Structs]: structs.html
[Traits (`where` clause)]: traits.html#where-clause
[Traits (Multiple Trait Bounds)]: traits.html#multiple-trait-bounds
[Traits (`where` clause)]: traits.html#Where%20clause
[Traits (Multiple Trait Bounds)]: traits.html#Multiple%20trait%20bounds
[Traits]: traits.html
[Universal Function Call Syntax]: ufcs.html
[Universal Function Call Syntax (Angle-bracket Form)]: ufcs.html#angle-bracket-form
[Universal Function Call Syntax (Angle-bracket Form)]: ufcs.html#Angle-bracket%20Form
[Unsafe]: unsafe.html
[Unsized Types (`?Sized`)]: unsized-types.html#sized
[Unsized Types (`?Sized`)]: unsized-types.html#Sized
[Variable Bindings]: variable-bindings.html

View File

@ -1,4 +1,4 @@
% Testing
# Testing
> Program testing can be a very effective way to show the presence of bugs, but
> it is hopelessly inadequate for showing their absence.

View File

@ -1,4 +1,4 @@
% The Stack and the Heap
# The Stack and the Heap
As a systems language, Rust operates at a low level. If youre coming from a
high-level language, there are some aspects of systems programming that you may

View File

@ -1,4 +1,4 @@
% Trait Objects
# Trait Objects
When code involves polymorphism, there needs to be a mechanism to determine
which specific version is actually run. This is called dispatch. There are

View File

@ -1,4 +1,4 @@
% Traits
# Traits
A trait is a language feature that tells the Rust compiler about
functionality a type must provide.
@ -81,7 +81,7 @@ Traits are useful because they allow a type to make certain promises about its
behavior. Generic functions can exploit this to constrain, or [bound][bounds], the types they
accept. Consider this function, which does not compile:
[bounds]: glossary.html#bounds
[bounds]: glossary.html#Bounds
```rust,ignore
fn print_area<T>(shape: T) {

View File

@ -1,4 +1,4 @@
% Type Aliases
# Type Aliases
The `type` keyword lets you declare an alias of another type:
@ -55,7 +55,7 @@ if x == y {
This compiles without error. Values of a `Num` type are the same as a value of
type `i32`, in every way. You can use [tuple struct] to really get a new type.
[tuple struct]: structs.html#tuple-structs
[tuple struct]: structs.html#Tuple%20structs
You can also use type aliases with generics:

View File

@ -1,4 +1,4 @@
% Universal Function Call Syntax
# Universal Function Call Syntax
Sometimes, functions can have the same names. Consider this code:

View File

@ -1,4 +1,4 @@
% Unsafe
# Unsafe
Rusts main draw is its powerful static guarantees about behavior. But safety
checks are conservative by nature: there are some programs that are actually

View File

@ -1,4 +1,4 @@
% Unsized Types
# Unsized Types
Most types have a particular size, in bytes, that is knowable at compile time.
For example, an `i32` is thirty-two bits big, or four bytes. However, there are

View File

@ -1,4 +1,4 @@
% Using Rust Without the Standard Library
# Using Rust Without the Standard Library
Rusts standard library provides a lot of useful functionality, but assumes
support for various features of its host system: threads, networking, heap

View File

@ -1,4 +1,4 @@
% Variable Bindings
# Variable Bindings
Virtually every non-'Hello World Rust program uses *variable bindings*. They
bind some value to a name, so it can be used later. `let` is

View File

@ -1,4 +1,4 @@
% Vectors
# Vectors
A vector is a dynamic or growable array, implemented as the standard
library type [`Vec<T>`][vec]. The `T` means that we can have vectors
@ -151,6 +151,6 @@ API documentation][vec].
[vec]: ../std/vec/index.html
[box]: ../std/boxed/index.html
[generic]: generics.html
[panic]: concurrency.html#panics
[panic]: concurrency.html#Panics
[get]: ../std/vec/struct.Vec.html#method.get
[get_mut]: ../std/vec/struct.Vec.html#method.get_mut

View File

@ -1,4 +1,4 @@
% The Rustonomicon
# The Rustonomicon
#### The Dark Arts of Advanced and Unsafe Rust Programming

View File

@ -1,5 +1,7 @@
# Summary
[Introduction](README.md)
* [Meet Safe and Unsafe](meet-safe-and-unsafe.md)
* [How Safe and Unsafe Interact](safe-unsafe-meaning.md)
* [Working with Unsafe](working-with-unsafe.md)

View File

@ -1,4 +1,4 @@
% Implementing Arc and Mutex
# Implementing Arc and Mutex
Knowing the theory is all fine and good, but the *best* way to understand
something is to use it. To better understand atomics and interior mutability,

View File

@ -1,4 +1,4 @@
% Atomics
# Atomics
Rust pretty blatantly just inherits C11's memory model for atomics. This is not
due to this model being particularly excellent or easy to understand. Indeed,

View File

@ -1,4 +1,4 @@
% Splitting Borrows
# Splitting Borrows
The mutual exclusion property of mutable references can be very limiting when
working with a composite structure. The borrow checker understands some basic

View File

@ -1,4 +1,4 @@
% Casts
# Casts
Casts are a superset of coercions: every coercion can be explicitly
invoked via a cast. However some conversions require a cast.

View File

@ -0,0 +1 @@
# Chapter 1

View File

@ -1,4 +1,4 @@
% Checked Uninitialized Memory
# Checked Uninitialized Memory
Like C, all stack variables in Rust are uninitialized until a value is
explicitly assigned to them. Unlike C, Rust statically prevents you from ever

View File

@ -1,4 +1,4 @@
% Coercions
# Coercions
Types can implicitly be coerced to change in certain contexts. These changes are
generally just *weakening* of types, largely focused around pointers and

View File

@ -1,4 +1,4 @@
% Concurrency and Parallelism
# Concurrency and Parallelism
Rust as a language doesn't *really* have an opinion on how to do concurrency or
parallelism. The standard library exposes OS threads and blocking sys-calls

View File

@ -1,4 +1,4 @@
% Constructors
# Constructors
There is exactly one way to create an instance of a user-defined type: name it,
and initialize all its fields at once:

View File

@ -1,4 +1,4 @@
% Type Conversions
# Type Conversions
At the end of the day, everything is just a pile of bits somewhere, and type
systems are just there to help us use those bits right. There are two common

View File

@ -1,4 +1,4 @@
% Data Representation in Rust
# Data Representation in Rust
Low-level programming cares a lot about data layout. It's a big deal. It also
pervasively influences the rest of the language, so we're going to start by

View File

@ -1,4 +1,4 @@
% Destructors
# Destructors
What the language *does* provide is full-blown automatic destructors through the
`Drop` trait, which provides the following method:

View File

@ -1,4 +1,4 @@
% The Dot Operator
# The Dot Operator
The dot operator will perform a lot of magic to convert types. It will perform
auto-referencing, auto-dereferencing, and coercion until types match.

View File

@ -1,4 +1,4 @@
% Drop Flags
# Drop Flags
The examples in the previous section introduce an interesting problem for Rust.
We have seen that it's possible to conditionally initialize, deinitialize, and

View File

@ -1,4 +1,4 @@
% Drop Check
# Drop Check
We have seen how lifetimes provide us some fairly simple rules for ensuring
that we never read dangling references. However up to this point we have only ever

View File

@ -1,4 +1,4 @@
% Exception Safety
# Exception Safety
Although programs should use unwinding sparingly, there's a lot of code that
*can* panic. If you unwrap a None, index out of bounds, or divide by 0, your

View File

@ -1,4 +1,4 @@
% Exotically Sized Types
# Exotically Sized Types
Most of the time, we think in terms of types with a fixed, positive size. This
is not always the case, however.

View File

@ -1,4 +1,4 @@
% Higher-Rank Trait Bounds (HRTBs)
# Higher-Rank Trait Bounds (HRTBs)
Rust's `Fn` traits are a little bit magic. For instance, we can write the
following code:

View File

@ -1,4 +1,4 @@
% Leaking
# Leaking
Ownership-based resource management is intended to simplify composition. You
acquire resources when you create the object, and you release the resources when

View File

@ -1,4 +1,4 @@
% Lifetime Elision
# Lifetime Elision
In order to make common patterns more ergonomic, Rust allows lifetimes to be
*elided* in function signatures.

View File

@ -1,4 +1,4 @@
% Limits of Lifetimes
# Limits of Lifetimes
Given the following code:
@ -78,4 +78,4 @@ TODO: other common problems? SEME regions stuff, mostly?
[ex2]: lifetimes.html#example-aliasing-a-mutable-reference
[ex2]: lifetimes.html#Example%3A%20aliasing%20a%20mutable%20reference

View File

@ -1,4 +1,4 @@
% Lifetimes
# Lifetimes
Rust enforces these rules through *lifetimes*. Lifetimes are effectively
just names for scopes somewhere in the program. Each reference,

View File

@ -1,4 +1,4 @@
% Meet Safe and Unsafe
# Meet Safe and Unsafe
Programmers in safe "high-level" languages face a fundamental dilemma. On one
hand, it would be *really* great to just say what you want and not worry about

Some files were not shown because too many files have changed in this diff Show More