From 77cc92b7c302d5ed6f7cc29d950a48c04e911bd9 Mon Sep 17 00:00:00 2001 From: appleJax Date: Sat, 9 Jan 2021 18:09:53 -0800 Subject: [PATCH] revert prettier autofix --- src/ch02-00-guessing-game-tutorial.md | 97 ++++++++++++++------------- src/ch14-03-cargo-workspaces.md | 75 +++++++++++---------- 2 files changed, 88 insertions(+), 84 deletions(-) diff --git a/src/ch02-00-guessing-game-tutorial.md b/src/ch02-00-guessing-game-tutorial.md index 493deb73a..3f9038398 100644 --- a/src/ch02-00-guessing-game-tutorial.md +++ b/src/ch02-00-guessing-game-tutorial.md @@ -14,7 +14,7 @@ correct, the game will print a congratulatory message and exit. ## Setting Up a New Project -To set up a new project, go to the _projects_ directory that you created in +To set up a new project, go to the *projects* directory that you created in Chapter 1 and make a new project using Cargo, like so: ```console @@ -26,7 +26,7 @@ The first command, `cargo new`, takes the name of the project (`guessing_game`) as the first argument. The second command changes to the new project’s directory. -Look at the generated _Cargo.toml_ file: +Look at the generated *Cargo.toml* file: Filename: Cargo.toml @@ -38,7 +38,7 @@ If the author information that Cargo obtained from your environment is not correct, fix that in the file and save it again. As you saw in Chapter 1, `cargo new` generates a “Hello, world!” program for -you. Check out the _src/main.rs_ file: +you. Check out the *src/main.rs* file: Filename: src/main.rs @@ -57,14 +57,14 @@ The `run` command comes in handy when you need to rapidly iterate on a project, as we’ll do in this game, quickly testing each iteration before moving on to the next one. -Reopen the _src/main.rs_ file. You’ll be writing all the code in this file. +Reopen the *src/main.rs* file. You’ll be writing all the code in this file. ## Processing a Guess The first part of the guessing game program will ask for user input, process that input, and check that the input is in the expected form. To start, we’ll allow the player to input a guess. Enter the code in Listing 2-1 into -_src/main.rs_. +*src/main.rs*. Filename: src/main.rs @@ -85,7 +85,7 @@ standard library (which is known as `std`): ``` By default, Rust brings only a few types into the scope of every program in -[the _prelude_][prelude]. If a type you want to use isn’t in the +[the *prelude*][prelude]. If a type you want to use isn’t in the prelude, you have to bring that type into scope explicitly with a `use` statement. Using the `std::io` library provides you with a number of useful features, including the ability to accept user input. @@ -122,7 +122,7 @@ Next, we’ll create a place to store the user input, like this: Now the program is getting interesting! There’s a lot going on in this little line. Notice that this is a `let` statement, which is used to create a -_variable_. Here’s another example: +*variable*. Here’s another example: ```rust,ignore let foo = bar; @@ -153,10 +153,10 @@ library that is a growable, UTF-8 encoded bit of text. [string]: ../std/string/struct.String.html -The `::` syntax in the `::new` line indicates that `new` is an _associated -function_ of the `String` type. An associated function is implemented on a type, +The `::` syntax in the `::new` line indicates that `new` is an *associated +function* of the `String` type. An associated function is implemented on a type, in this case `String`, rather than on a particular instance of a `String`. Some -languages call this a _static method_. +languages call this a *static method*. This `new` function creates a new, empty string. You’ll find a `new` function on many types, because it’s a common name for a function that makes a new value @@ -182,7 +182,8 @@ type that represents a handle to the standard input for your terminal. The next part of the code, `.read_line(&mut guess)`, calls the [`read_line`][read_line] method on the standard input handle to -get input from the user. We’re also passing one argument to `read_line`: `&mut guess`. +get input from the user. We’re also passing one argument to `read_line`: `&mut +guess`. [read_line]: ../std/io/struct.Stdin.html#method.read_line @@ -191,7 +192,7 @@ and place that into a string, so it takes that string as an argument. The string argument needs to be mutable so the method can change the string’s content by adding the user input. -The `&` indicates that this argument is a _reference_, which gives you a way to +The `&` indicates that this argument is a *reference*, which gives you a way to let multiple parts of your code access one piece of data without needing to copy that data into memory multiple times. References are a complex feature, and one of Rust’s major advantages is how safe and easy it is to use @@ -231,9 +232,9 @@ as well as specific versions for submodules, such as `io::Result`. [ioresult]: ../std/io/type.Result.html [result]: ../std/result/enum.Result.html -The `Result` types are [_enumerations_][enums], often referred -to as _enums_. An enumeration is a type that can have a fixed set of values, -and those values are called the enum’s _variants_. Chapter 6 will cover enums +The `Result` types are [*enumerations*][enums], often referred +to as *enums*. An enumeration is a type that can have a fixed set of values, +and those values are called the enum’s *variants*. Chapter 6 will cover enums in more detail. [enums]: ch06-00-enums.html @@ -332,12 +333,12 @@ library. However, the Rust team does provide a [`rand` crate][randcrate]. ### Using a Crate to Get More Functionality Remember that a crate is a collection of Rust source code files. -The project we’ve been building is a _binary crate_, which is an executable. -The `rand` crate is a _library crate_, which contains code intended to be +The project we’ve been building is a *binary crate*, which is an executable. +The `rand` crate is a *library crate*, which contains code intended to be used in other programs. Cargo’s use of external crates is where it really shines. Before we can write -code that uses `rand`, we need to modify the _Cargo.toml_ file to include the +code that uses `rand`, we need to modify the *Cargo.toml* file to include the `rand` crate as a dependency. Open that file now and add the following line to the bottom beneath the `[dependencies]` section header that Cargo created for you: @@ -354,12 +355,12 @@ you: {{#include ../listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.toml:9:}} ``` -In the _Cargo.toml_ file, everything that follows a header is part of a section +In the *Cargo.toml* file, everything that follows a header is part of a section that continues until another section starts. The `[dependencies]` section is where you tell Cargo which external crates your project depends on and which versions of those crates you require. In this case, we’ll specify the `rand` crate with the semantic version specifier `0.8.1`. Cargo understands [Semantic -Versioning][semver] (sometimes called _SemVer_), which is a +Versioning][semver] (sometimes called *SemVer*), which is a standard for writing version numbers. The number `0.8.1` is actually shorthand for `^0.8.1`, which means any version that is at least `0.8.1` but below `0.9.0`. Cargo considers these versions to have public APIs compatible with @@ -399,7 +400,7 @@ You may see different version numbers (but they will all be compatible with the code, thanks to SemVer!), different lines (depending on the operating system), and the lines may be in a different order. Now that we have an external dependency, Cargo fetches the latest versions of -everything from the _registry_, which is a copy of data from +everything from the *registry*, which is a copy of data from [Crates.io][cratesio]. Crates.io is where people in the Rust ecosystem post their open source Rust projects for others to use. @@ -414,11 +415,11 @@ them and then compiles the project with the dependencies available. If you immediately run `cargo build` again without making any changes, you won’t get any output aside from the `Finished` line. Cargo knows it has already downloaded and compiled the dependencies, and you haven’t changed anything -about them in your _Cargo.toml_ file. Cargo also knows that you haven’t changed +about them in your *Cargo.toml* file. Cargo also knows that you haven’t changed anything about your code, so it doesn’t recompile that either. With nothing to do, it simply exits. -If you open up the _src/main.rs_ file, make a trivial change, and then save it +If you open up the *src/main.rs* file, make a trivial change, and then save it and build again, you’ll only see two lines of output: