Port TRPL to mdbook

1. move everything under a src directory
2. add README.md to the SUMMARY.md
This commit is contained in:
Steve Klabnik 2017-02-07 19:07:28 -05:00
parent a076961fd0
commit e943e68a47
71 changed files with 146 additions and 146 deletions

View File

@ -1,70 +0,0 @@
# Summary
* [Getting Started](getting-started.md)
* [Tutorial: Guessing Game](guessing-game.md)
* [Syntax and Semantics](syntax-and-semantics.md)
* [Variable Bindings](variable-bindings.md)
* [Functions](functions.md)
* [Primitive Types](primitive-types.md)
* [Comments](comments.md)
* [if](if.md)
* [Loops](loops.md)
* [Vectors](vectors.md)
* [Ownership](ownership.md)
* [References and Borrowing](references-and-borrowing.md)
* [Lifetimes](lifetimes.md)
* [Mutability](mutability.md)
* [Structs](structs.md)
* [Enums](enums.md)
* [Match](match.md)
* [Patterns](patterns.md)
* [Method Syntax](method-syntax.md)
* [Strings](strings.md)
* [Generics](generics.md)
* [Traits](traits.md)
* [Drop](drop.md)
* [if let](if-let.md)
* [Trait Objects](trait-objects.md)
* [Closures](closures.md)
* [Universal Function Call Syntax](ufcs.md)
* [Crates and Modules](crates-and-modules.md)
* [`const` and `static`](const-and-static.md)
* [Attributes](attributes.md)
* [`type` aliases](type-aliases.md)
* [Casting between types](casting-between-types.md)
* [Associated Types](associated-types.md)
* [Unsized Types](unsized-types.md)
* [Operators and Overloading](operators-and-overloading.md)
* [Deref coercions](deref-coercions.md)
* [Macros](macros.md)
* [Raw Pointers](raw-pointers.md)
* [`unsafe`](unsafe.md)
* [Effective Rust](effective-rust.md)
* [The Stack and the Heap](the-stack-and-the-heap.md)
* [Testing](testing.md)
* [Conditional Compilation](conditional-compilation.md)
* [Documentation](documentation.md)
* [Iterators](iterators.md)
* [Concurrency](concurrency.md)
* [Error Handling](error-handling.md)
* [Choosing your Guarantees](choosing-your-guarantees.md)
* [FFI](ffi.md)
* [Borrow and AsRef](borrow-and-asref.md)
* [Release Channels](release-channels.md)
* [Using Rust without the standard library](using-rust-without-the-standard-library.md)
* [Procedural Macros (and custom derive)](procedural-macros.md)
* [Nightly Rust](nightly-rust.md)
* [Compiler Plugins](compiler-plugins.md)
* [Inline Assembly](inline-assembly.md)
* [No stdlib](no-stdlib.md)
* [Intrinsics](intrinsics.md)
* [Lang items](lang-items.md)
* [Advanced linking](advanced-linking.md)
* [Benchmark Tests](benchmark-tests.md)
* [Box Syntax and Patterns](box-syntax-and-patterns.md)
* [Slice Patterns](slice-patterns.md)
* [Associated Constants](associated-constants.md)
* [Custom Allocators](custom-allocators.md)
* [Glossary](glossary.md)
* [Syntax Index](syntax-index.md)
* [Bibliography](bibliography.md)

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,3 +1,72 @@
# Summary
- [Chapter 1](./chapter_1.md)
[Introduction](README.md)
* [Getting Started](getting-started.md)
* [Tutorial: Guessing Game](guessing-game.md)
* [Syntax and Semantics](syntax-and-semantics.md)
* [Variable Bindings](variable-bindings.md)
* [Functions](functions.md)
* [Primitive Types](primitive-types.md)
* [Comments](comments.md)
* [if](if.md)
* [Loops](loops.md)
* [Vectors](vectors.md)
* [Ownership](ownership.md)
* [References and Borrowing](references-and-borrowing.md)
* [Lifetimes](lifetimes.md)
* [Mutability](mutability.md)
* [Structs](structs.md)
* [Enums](enums.md)
* [Match](match.md)
* [Patterns](patterns.md)
* [Method Syntax](method-syntax.md)
* [Strings](strings.md)
* [Generics](generics.md)
* [Traits](traits.md)
* [Drop](drop.md)
* [if let](if-let.md)
* [Trait Objects](trait-objects.md)
* [Closures](closures.md)
* [Universal Function Call Syntax](ufcs.md)
* [Crates and Modules](crates-and-modules.md)
* [`const` and `static`](const-and-static.md)
* [Attributes](attributes.md)
* [`type` aliases](type-aliases.md)
* [Casting between types](casting-between-types.md)
* [Associated Types](associated-types.md)
* [Unsized Types](unsized-types.md)
* [Operators and Overloading](operators-and-overloading.md)
* [Deref coercions](deref-coercions.md)
* [Macros](macros.md)
* [Raw Pointers](raw-pointers.md)
* [`unsafe`](unsafe.md)
* [Effective Rust](effective-rust.md)
* [The Stack and the Heap](the-stack-and-the-heap.md)
* [Testing](testing.md)
* [Conditional Compilation](conditional-compilation.md)
* [Documentation](documentation.md)
* [Iterators](iterators.md)
* [Concurrency](concurrency.md)
* [Error Handling](error-handling.md)
* [Choosing your Guarantees](choosing-your-guarantees.md)
* [FFI](ffi.md)
* [Borrow and AsRef](borrow-and-asref.md)
* [Release Channels](release-channels.md)
* [Using Rust without the standard library](using-rust-without-the-standard-library.md)
* [Procedural Macros (and custom derive)](procedural-macros.md)
* [Nightly Rust](nightly-rust.md)
* [Compiler Plugins](compiler-plugins.md)
* [Inline Assembly](inline-assembly.md)
* [No stdlib](no-stdlib.md)
* [Intrinsics](intrinsics.md)
* [Lang items](lang-items.md)
* [Advanced linking](advanced-linking.md)
* [Benchmark Tests](benchmark-tests.md)
* [Box Syntax and Patterns](box-syntax-and-patterns.md)
* [Slice Patterns](slice-patterns.md)
* [Associated Constants](associated-constants.md)
* [Custom Allocators](custom-allocators.md)
* [Glossary](glossary.md)
* [Syntax Index](syntax-index.md)
* [Bibliography](bibliography.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.
@ -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

@ -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

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.

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

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

View File

@ -1,4 +1,4 @@
% Foreign Function Interface
# Foreign Function Interface
# Introduction

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,

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.

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

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

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

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

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

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

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

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.

View File

@ -1,4 +1,4 @@
% Type Aliases
# Type Aliases
The `type` keyword lets you declare an alias of another type:

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