mirror of
https://github.com/rust-lang/book.git
synced 2026-12-03 10:55:06 -06:00
Merge pull request #297 from evuez/update-chapter-xx
Convert "Chapter XX" to correct numbers
This commit is contained in:
@@ -101,7 +101,7 @@ that it’s indented with four spaces, not a tab.
|
|||||||
The second important part is `println!`. This is calling a Rust *macro*,
|
The second important part is `println!`. This is calling a Rust *macro*,
|
||||||
which is how metaprogramming is done in Rust. If it were calling a function
|
which is how metaprogramming is done in Rust. If it were calling a function
|
||||||
instead, it would look like this: `println` (without the `!`). We'll discuss
|
instead, it would look like this: `println` (without the `!`). We'll discuss
|
||||||
Rust macros in more detail in Chapter XX, but for now you just need to know
|
Rust macros in more detail in Chapter 24, but for now you just need to know
|
||||||
that when you see a `!` that means that you’re calling a macro instead of a
|
that when you see a `!` that means that you’re calling a macro instead of a
|
||||||
normal function.
|
normal function.
|
||||||
|
|
||||||
|
|||||||
@@ -487,7 +487,7 @@ available and reevaluate your `rand` requirements according to the new version
|
|||||||
you specified.
|
you specified.
|
||||||
|
|
||||||
There’s a lot more to say about [Cargo][doccargo]<!-- ignore --> and [its
|
There’s a lot more to say about [Cargo][doccargo]<!-- ignore --> and [its
|
||||||
ecosystem][doccratesio]<!-- ignore --> that Chapter XX will discuss, but for
|
ecosystem][doccratesio]<!-- ignore --> that Chapter 14 will discuss, but for
|
||||||
now, that’s all you need to know. Cargo makes it very easy to reuse libraries,
|
now, that’s all you need to know. Cargo makes it very easy to reuse libraries,
|
||||||
so Rustaceans are able to write smaller projects that are assembled from a
|
so Rustaceans are able to write smaller projects that are assembled from a
|
||||||
number of packages.
|
number of packages.
|
||||||
@@ -659,7 +659,7 @@ expression fits that arm’s pattern. Rust takes the value given to `match` and
|
|||||||
looks through each arm’s pattern in turn. The `match` construct and patterns
|
looks through each arm’s pattern in turn. The `match` construct and patterns
|
||||||
are powerful features in Rust that let you express a variety of situations your
|
are powerful features in Rust that let you express a variety of situations your
|
||||||
code might encounter and helps ensure that you handle them all. These features
|
code might encounter and helps ensure that you handle them all. These features
|
||||||
will be covered in detail in Chapter 6 and Chapter XX, respectively.
|
will be covered in detail in Chapter 6 and Chapter 19, respectively.
|
||||||
|
|
||||||
Let’s walk through an example of what would happen with the `match` expression
|
Let’s walk through an example of what would happen with the `match` expression
|
||||||
used here. Say that the user has guessed 50, and the randomly generated secret
|
used here. Say that the user has guessed 50, and the randomly generated secret
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ explore how Rust knows when to clean that data up.
|
|||||||
We’re going to use `String` as the example here and concentrate on the parts of
|
We’re going to use `String` as the example here and concentrate on the parts of
|
||||||
`String` that relate to ownership. These aspects also apply to other complex
|
`String` that relate to ownership. These aspects also apply to other complex
|
||||||
data types provided by the standard library and that you create. We’ll go into
|
data types provided by the standard library and that you create. We’ll go into
|
||||||
more depth about `String` specifically in Chapter XX.
|
more depth about `String` specifically in Chapter 8.
|
||||||
|
|
||||||
We’ve already seen string literals, where a string value is hard-coded into our
|
We’ve already seen string literals, where a string value is hard-coded into our
|
||||||
program. String literals are convenient, but they aren’t always suitable for
|
program. String literals are convenient, but they aren’t always suitable for
|
||||||
@@ -353,7 +353,7 @@ copying can be assumed to be inexpensive.
|
|||||||
|
|
||||||
If we *do* want to deeply copy the `String`’s data and not just the `String`
|
If we *do* want to deeply copy the `String`’s data and not just the `String`
|
||||||
itself, there’s a common method for that: `clone`. We will discuss methods in
|
itself, there’s a common method for that: `clone`. We will discuss methods in
|
||||||
the section on [`structs` in Chapter XX][structs]<!-- ignore -->, but they’re a
|
the section on [`structs` in Chapter 5][structs]<!-- ignore -->, but they’re a
|
||||||
common enough feature in many programming languages that you have probably seen
|
common enough feature in many programming languages that you have probably seen
|
||||||
them before.
|
them before.
|
||||||
|
|
||||||
@@ -398,7 +398,7 @@ deep and shallow copying here, so calling `clone` wouldn’t do anything
|
|||||||
differently from the usual shallow copying and we can leave it out.
|
differently from the usual shallow copying and we can leave it out.
|
||||||
|
|
||||||
Rust has a special annotation called the `Copy` trait that we can place on
|
Rust has a special annotation called the `Copy` trait that we can place on
|
||||||
types like these (we’ll talk more about traits in Chapter XX). If a type has
|
types like these (we’ll talk more about traits in Chapter 23). If a type has
|
||||||
the `Copy` trait, an older variable is still usable after assignment. Rust will
|
the `Copy` trait, an older variable is still usable after assignment. Rust will
|
||||||
not let us annotate a type with the `Copy` trait if the type, or any of its
|
not let us annotate a type with the `Copy` trait if the type, or any of its
|
||||||
parts, has implemented `drop`. If the type needs something special to happen
|
parts, has implemented `drop`. If the type needs something special to happen
|
||||||
|
|||||||
@@ -257,7 +257,7 @@ error: aborting due to previous error
|
|||||||
```
|
```
|
||||||
|
|
||||||
This error message refers to a feature we haven’t learned about yet:
|
This error message refers to a feature we haven’t learned about yet:
|
||||||
*lifetimes*. We’ll discuss lifetimes in detail in Chapter XX, but, disregarding
|
*lifetimes*. We’ll discuss lifetimes in detail in Chapter 20, but, disregarding
|
||||||
the parts about lifetimes, the message does contain the key to why this code is
|
the parts about lifetimes, the message does contain the key to why this code is
|
||||||
a problem: `this function’s return type contains a borrowed value, but there is
|
a problem: `this function’s return type contains a borrowed value, but there is
|
||||||
no value for it to be borrowed from`.
|
no value for it to be borrowed from`.
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ array of bytes using the `as_bytes` method.
|
|||||||
for (i, &item) in bytes.iter().enumerate() {
|
for (i, &item) in bytes.iter().enumerate() {
|
||||||
```
|
```
|
||||||
|
|
||||||
We will be discussing iterators in more detail in Chapter XX, but for now, know
|
We will be discussing iterators in more detail in Chapter 16, but for now, know
|
||||||
that `iter` is a method that returns each element in a collection, and
|
that `iter` is a method that returns each element in a collection, and
|
||||||
`enumerate` modifies the result of `iter` and returns each element as part
|
`enumerate` modifies the result of `iter` and returns each element as part
|
||||||
of a tuple instead, where the first element of the tuple is the index, and the
|
of a tuple instead, where the first element of the tuple is the index, and the
|
||||||
@@ -355,7 +355,7 @@ let slice = &a[1..3];
|
|||||||
This slice has the type `&[i32]`. It works the exact same way as string slices
|
This slice has the type `&[i32]`. It works the exact same way as string slices
|
||||||
do, by storing a reference to the first element and a length. You’ll use this
|
do, by storing a reference to the first element and a length. You’ll use this
|
||||||
kind of slice for all sorts of other collections. We’ll discuss these in detail
|
kind of slice for all sorts of other collections. We’ll discuss these in detail
|
||||||
when we talk about vectors in Chapter XX.
|
when we talk about vectors in Chapter 8.
|
||||||
|
|
||||||
## Summary
|
## Summary
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ their name, they can take arguments and return values, and they contain some
|
|||||||
code that gets run when they're called from somewhere else. Methods are
|
code that gets run when they're called from somewhere else. Methods are
|
||||||
different from functions, however, because they're defined within the context
|
different from functions, however, because they're defined within the context
|
||||||
of a struct (or an enum or a trait object, which we will cover in Chapters 6
|
of a struct (or an enum or a trait object, which we will cover in Chapters 6
|
||||||
and XX respectively), and their first argument is always `self`, which
|
and 23 respectively), and their first argument is always `self`, which
|
||||||
represents the instance of the struct that the method is being called on.
|
represents the instance of the struct that the method is being called on.
|
||||||
|
|
||||||
### Defining Methods
|
### Defining Methods
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ always handle every possible case.
|
|||||||
Using an enum for storing different types in a vector does imply that we need
|
Using an enum for storing different types in a vector does imply that we need
|
||||||
to know the set of types we'll want to store at compile time. If that's not the
|
to know the set of types we'll want to store at compile time. If that's not the
|
||||||
case, instead of an enum, we can use a trait object. We'll learn about those in
|
case, instead of an enum, we can use a trait object. We'll learn about those in
|
||||||
Chapter XX.
|
Chapter 23.
|
||||||
|
|
||||||
Now that we've gone over some of the most common ways to use vectors, be sure
|
Now that we've gone over some of the most common ways to use vectors, be sure
|
||||||
to take a look at the API documentation for other useful methods defined on
|
to take a look at the API documentation for other useful methods defined on
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ The `Ok` variant indicates a successful result, and `Err` indicates an
|
|||||||
unsuccessful result. These two variants each contain one thing: in `Ok`'s case,
|
unsuccessful result. These two variants each contain one thing: in `Ok`'s case,
|
||||||
it's the successful return value. With `Err`, it's some value that represents
|
it's the successful return value. With `Err`, it's some value that represents
|
||||||
the error. The `T` and `E` are generic type parameters; we'll go into generics
|
the error. The `T` and `E` are generic type parameters; we'll go into generics
|
||||||
in more detail in Chapter XX. What you need to know for right now is that the
|
in more detail in Chapter 10. What you need to know for right now is that the
|
||||||
`Result` type is defined such that it can have the same behavior for any type
|
`Result` type is defined such that it can have the same behavior for any type
|
||||||
`T` that is what we want to return in the success case, and any type `E` that
|
`T` that is what we want to return in the success case, and any type `E` that
|
||||||
is what we want to return in the error case.
|
is what we want to return in the error case.
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ that would be a violation of the contract that `Guess::new` is relying on. This
|
|||||||
function needs to signal to the calling code that it has a bug somewhere
|
function needs to signal to the calling code that it has a bug somewhere
|
||||||
leading to the contract violation. The conditions in which `Guess::new` might
|
leading to the contract violation. The conditions in which `Guess::new` might
|
||||||
panic should be discussed in its public-facing API documentation, which we will
|
panic should be discussed in its public-facing API documentation, which we will
|
||||||
cover in Chapter XX.
|
cover in Chapter 14.
|
||||||
|
|
||||||
Important to note is the `value` field of the `Guess` struct is private, so
|
Important to note is the `value` field of the `Guess` struct is private, so
|
||||||
code using this struct may not set that value directly. Callers *must* use the
|
code using this struct may not set that value directly. Callers *must* use the
|
||||||
|
|||||||
Reference in New Issue
Block a user