Skip to content

Commit

Permalink
Merge pull request #13 from rust-lang/master
Browse files Browse the repository at this point in the history
Merge pull request rust-lang#2380 from EvanCarroll/master
  • Loading branch information
fengjixuchui authored Jun 24, 2020
2 parents ae87312 + c9d5db3 commit 124d7c5
Show file tree
Hide file tree
Showing 20 changed files with 91 additions and 77 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Install mdbook
run: |
mkdir bin
curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.3.5/mdbook-v0.3.5-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=bin
curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.3.7/mdbook-v0.3.7-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=bin
echo "##[add-path]$(pwd)/bin"
- name: Report versions
run: |
Expand All @@ -41,7 +41,7 @@ jobs:
- name: Install mdbook
run: |
mkdir bin
curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.3.5/mdbook-v0.3.5-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=bin
curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.3.7/mdbook-v0.3.7-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=bin
echo "##[add-path]$(pwd)/bin"
- name: Report versions
run: |
Expand All @@ -51,7 +51,7 @@ jobs:
- name: Spellcheck
run: bash ci/spellcheck.sh list
- name: Lint for local file paths
run: |
run: |
mdbook build
cargo run --bin lfp src
- name: Validate references
Expand All @@ -61,4 +61,4 @@ jobs:
curl -sSLo linkcheck.sh \
https://raw.githubusercontent.com/rust-lang/rust/master/src/tools/linkchecker/linkcheck.sh
# Cannot use --all here because of the generated redirect pages aren't available.
sh linkcheck.sh book
sh linkcheck.sh book
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ comments for any suggestions or corrections!

If you're looking for ways to help that don't involve large amounts of
reading or writing, check out the [open issues with the E-help-wanted
label][help-wanted]. These might be small fixes to the text Rust code,
label][help-wanted]. These might be small fixes to the text, Rust code,
frontend code, or shell scripts that would help us be more efficient or
enhance the book in some way!

Expand Down
1 change: 1 addition & 0 deletions ci/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ chXX
chYY
clippy
clippy's
cmdlet
coercions
combinator
ConcreteType
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// ANCHOR: here
fn largest(list: &[i32]) -> i32 {
let mut largest = list[0];
fn largest(list: &[i32]) -> &i32 {
let mut largest = &list[0];

for &item in list {
for item in list {
if item > largest {
largest = item;
}
Expand All @@ -17,15 +17,15 @@ fn main() {
let result = largest(&number_list);
println!("The largest number is {}", result);
// ANCHOR_END: here
assert_eq!(result, 100);
assert_eq!(result, &100);
// ANCHOR: here

let number_list = vec![102, 34, 6000, 89, 54, 2, 43, 8];

let result = largest(&number_list);
println!("The largest number is {}", result);
// ANCHOR_END: here
assert_eq!(result, 6000);
assert_eq!(result, &6000);
// ANCHOR: here
}
// ANCHOR_END: here
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// ANCHOR: here
fn largest_i32(list: &[i32]) -> i32 {
let mut largest = list[0];
fn largest_i32(list: &[i32]) -> &i32 {
let mut largest = &list[0];

for &item in list {
for item in list {
if item > largest {
largest = item;
}
Expand All @@ -11,10 +11,10 @@ fn largest_i32(list: &[i32]) -> i32 {
largest
}

fn largest_char(list: &[char]) -> char {
let mut largest = list[0];
fn largest_char(list: &[char]) -> &char {
let mut largest = &list[0];

for &item in list {
for item in list {
if item > largest {
largest = item;
}
Expand All @@ -29,15 +29,15 @@ fn main() {
let result = largest_i32(&number_list);
println!("The largest number is {}", result);
// ANCHOR_END: here
assert_eq!(result, 100);
assert_eq!(result, &100);
// ANCHOR: here

let char_list = vec!['y', 'm', 'a', 'q'];

let result = largest_char(&char_list);
println!("The largest char is {}", result);
// ANCHOR_END: here
assert_eq!(result, 'y');
assert_eq!(result, &'y');
// ANCHOR: here
}
// ANCHOR_END: here
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
fn largest<T>(list: &[T]) -> T {
fn largest<T>(list: &[T]) -> &T {
let mut largest = list[0];

for &item in list {
for item in list {
if item > largest {
largest = item;
}
Expand Down
2 changes: 1 addition & 1 deletion listings/ch13-functional-features/listing-13-26/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct Config {

// ANCHOR: here
impl Config {
pub fn new(mut args: std::env::Args) -> Result<Config, &'static str> {
pub fn new(mut args: env::Args) -> Result<Config, &'static str> {
// --snip--
// ANCHOR_END: here
if args.len() < 3 {
Expand Down
2 changes: 1 addition & 1 deletion listings/ch13-functional-features/listing-13-27/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct Config {

// ANCHOR: here
impl Config {
pub fn new(mut args: std::env::Args) -> Result<Config, &'static str> {
pub fn new(mut args: env::Args) -> Result<Config, &'static str> {
args.next();

let query = match args.next() {
Expand Down
4 changes: 2 additions & 2 deletions listings/ch15-smart-pointers/listing-15-24/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ $ cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.63s
Running `target/debug/cons-list`
a after = Cons(RefCell { value: 15 }, Nil)
b after = Cons(RefCell { value: 6 }, Cons(RefCell { value: 15 }, Nil))
c after = Cons(RefCell { value: 10 }, Cons(RefCell { value: 15 }, Nil))
b after = Cons(RefCell { value: 3 }, Cons(RefCell { value: 15 }, Nil))
c after = Cons(RefCell { value: 4 }, Cons(RefCell { value: 15 }, Nil))
4 changes: 2 additions & 2 deletions listings/ch15-smart-pointers/listing-15-24/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ fn main() {

let a = Rc::new(Cons(Rc::clone(&value), Rc::new(Nil)));

let b = Cons(Rc::new(RefCell::new(6)), Rc::clone(&a));
let c = Cons(Rc::new(RefCell::new(10)), Rc::clone(&a));
let b = Cons(Rc::new(RefCell::new(3)), Rc::clone(&a));
let c = Cons(Rc::new(RefCell::new(4)), Rc::clone(&a));

*value.borrow_mut() += 10;

Expand Down
1 change: 1 addition & 0 deletions src/appendix-06-translation.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ For resources in languages other than English. Most are still in progress; see
- [ελληνική](https://github.com/TChatzigiannakis/rust-book-greek)
- [Svenska](https://github.com/sebras/book)
- [Farsi](https://github.com/pomokhtari/rust-book-fa)
- [Deutsch](https://github.com/rust-lang-de/rustbook-de)
3 changes: 2 additions & 1 deletion src/ch01-03-hello-cargo.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,9 @@ build` when they’re ready to use the executable.

Let’s recap what we’ve learned so far about Cargo:

* We can build a project using `cargo build` or `cargo check`.
* We can build a project using `cargo build`.
* We can build and run a project in one step using `cargo run`.
* We can build a project without producing a binary to check for errors using `cargo check`.
* Instead of saving the result of the build in the same directory as our code,
Cargo stores it in the *target/debug* directory.

Expand Down
2 changes: 1 addition & 1 deletion src/ch06-02-match.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ list before the `_` placeholder.
However, the `match` expression can be a bit wordy in a situation in which we
care about only *one* of the cases. For this situation, Rust provides `if let`.

More about patterns, and matching can be found in [chapter 18][ch18-00-patterns].
More about patterns and matching can be found in [chapter 18][ch18-00-patterns].

[ch18-00-patterns]:
ch18-00-patterns.html
2 changes: 1 addition & 1 deletion src/ch08-01-vectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ and any other references to the contents of the vector remain valid. Recall the
rule that states you can’t have mutable and immutable references in the same
scope. That rule applies in Listing 8-7, where we hold an immutable reference to
the first element in a vector and try to add an element to the end, which won’t
work.
work if we also try to refer to that element later in the function:

```rust,ignore,does_not_compile
{{#rustdoc_include ../listings/ch08-common-collections/listing-08-07/src/main.rs:here}}
Expand Down
5 changes: 3 additions & 2 deletions src/ch10-01-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ to declare the type parameter name before we use it. To define the generic
between the name of the function and the parameter list, like this:

```rust,ignore
fn largest<T>(list: &[T]) -> T {
fn largest<T>(list: &[T]) -> &T {
```

We read this definition as: the function `largest` is generic over some type
`T`. This function has one parameter named `list`, which is a slice of values
of type `T`. The `largest` function will return a value of the same type `T`.
of type `T`. The `largest` function will return a reference to a value of the
same type `T`.

Listing 10-5 shows the combined `largest` function definition using the generic
data type in its signature. The listing also shows how we can call the function
Expand Down
19 changes: 9 additions & 10 deletions src/ch10-03-lifetime-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,10 @@ function to find the longer of two string slices</span>

Note that we want the function to take string slices, which are references,
because we don’t want the `longest` function to take ownership of its
parameters. We want to allow the function to accept slices of a `String` (the
type stored in the variable `string1`) as well as string literals (which is
what variable `string2` contains).

Refer to the [“String Slices as Parameters”][string-slices-as-parameters]<!--
ignore --> section in Chapter 4 for more discussion about why the parameters we
use in Listing 10-20 are the ones we want.
parameters. Refer to the [“String Slices as
Parameters”][string-slices-as-parameters]<!-- ignore --> section in Chapter 4
for more discussion about why the parameters we use in Listing 10-20 are the
ones we want.

If we try to implement the `longest` function as shown in Listing 10-21, it
won’t compile.
Expand Down Expand Up @@ -609,11 +606,13 @@ analysis happens at compile time, which doesn’t affect runtime performance!

Believe it or not, there is much more to learn on the topics we discussed in
this chapter: Chapter 17 discusses trait objects, which are another way to use
traits. Chapter 19 covers more complex scenarios involving lifetime annotations
as well as some advanced type system features. But next, you’ll learn how to
write tests in Rust so you can make sure your code is working the way it should.
traits. There are also more complex scenarios involving lifetime annotations
that you will only need in very advanced scenarios; for those, you should read
the [Rust Reference][reference]. But next, you’ll learn how to write tests in
Rust so you can make sure your code is working the way it should.

[references-and-borrowing]:
ch04-02-references-and-borrowing.html#references-and-borrowing
[string-slices-as-parameters]:
ch04-03-slices.html#string-slices-as-parameters
[reference]: ../reference/index.html
19 changes: 14 additions & 5 deletions src/ch12-05-working-with-environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ function to lowercase the query and the line before comparing them</span>
First, we lowercase the `query` string and store it in a shadowed variable with
the same name. Calling `to_lowercase` on the query is necessary so no matter
whether the user’s query is `"rust"`, `"RUST"`, `"Rust"`, or `"rUsT"`, we’ll
treat the query as if it were `"rust"` and be insensitive to the case.
treat the query as if it were `"rust"` and be insensitive to the case. While
`to_lowercase` will handle basic Unicode, it won't be 100% accurate. If we were
writing a real application, we'd want to do a bit more work here, but this section
is about environment variables, not Unicode, so we'll leave it at that here.

Note that `query` is now a `String` rather than a string slice, because calling
`to_lowercase` creates new data rather than referencing existing data. Say the
Expand Down Expand Up @@ -154,12 +157,18 @@ the word “to” in all lowercase:
Looks like that still works! Now, let’s run the program with `CASE_INSENSITIVE`
set to `1` but with the same query `to`.

If youre using PowerShell, you will need to set the environment variable and
run the program in two commands rather than one:
If you're using PowerShell, you will need to set the environment
variable and run the program as separate commands:

```console
$ $env:CASE_INSENSITIVE=1
$ cargo run to poem.txt
PS> $Env:CASE_INSENSITIVE=1; cargo run to poem.txt
```

This will make `CASE_INSENSITIVE` persist for the remainder of your shell
session. It can be unset with the `Remove-Item` cmdlet:

```console
PS> Remove-Item Env:CASE_INSENSITIVE
```

We should get lines that contain “to” that might have uppercase letters:
Expand Down
Loading

0 comments on commit 124d7c5

Please sign in to comment.