diff --git a/src/appendix-01-keywords.md b/src/appendix-01-keywords.md index b848945915..0cbaf316a5 100644 --- a/src/appendix-01-keywords.md +++ b/src/appendix-01-keywords.md @@ -2,7 +2,7 @@ The following list contains keywords that are reserved for current or future use by the Rust language. As such, they cannot be used as identifiers (except -as raw identifiers as we’ll discuss in the “[Raw +as raw identifiers, as we’ll discuss in the “[Raw Identifiers][raw-identifiers]” section). Identifiers are names of functions, variables, parameters, struct fields, modules, crates, constants, macros, static values, attributes, types, traits, or lifetimes. @@ -81,7 +81,7 @@ Rust for potential future use. ### Raw Identifiers *Raw identifiers* are the syntax that lets you use keywords where they wouldn’t -normally be allowed. You use a raw identifier by prefixing a keyword with `r#`. +usually be allowed. You use a raw identifier by prefixing a keyword with `r#`. For example, `match` is a keyword. If you try to compile the following function that uses `match` as its name: @@ -106,7 +106,7 @@ error: expected identifier, found keyword `match` The error shows that you can’t use the keyword `match` as the function identifier. To use `match` as a function name, you need to use the raw -identifier syntax, like this: +identifier syntax like this: Filename: src/main.rs @@ -121,11 +121,11 @@ fn main() { ``` This code will compile without any errors. Note the `r#` prefix on the function -name in its definition as well as where the function is called in `main`. +name in its definition, as well as where the function is called in `main`. Raw identifiers allow you to use any word you choose as an identifier, even if that word happens to be a reserved keyword. This gives us more freedom to -choose identifier names, as well as lets us integrate with programs written in +choose identifier names and lets us integrate with programs written in a language where these words aren’t keywords. In addition, raw identifiers allow you to use libraries written in a different Rust edition than your crate uses. For example, `try` isn’t a keyword in the 2015 edition but is in the 2018 diff --git a/src/appendix-02-operators.md b/src/appendix-02-operators.md index bc770c703e..eff7f1de65 100644 --- a/src/appendix-02-operators.md +++ b/src/appendix-02-operators.md @@ -87,7 +87,7 @@ locations. | `"..."` | String literal | | `r"..."`, `r#"..."#`, `r##"..."##`, etc. | Raw string literal, escape characters not processed | | `b"..."` | Byte string literal; constructs an array of bytes instead of a string | -| `br"..."`, `br#"..."#`, `br##"..."##`, etc. | Raw byte string literal, combination of raw and byte string literal | +| `br"..."`, `br#"..."#`, `br##"..."##`, etc. | Raw byte string literal, a combination of raw and byte string literal | | `'...'` | Character literal | | `b'...'` | ASCII byte literal | | |...| expr | Closure | @@ -119,7 +119,7 @@ parameters. | Symbol | Explanation | |--------|-------------| | `path<...>` | Specifies parameters to generic type in a type (e.g., `Vec`) | -| `path::<...>`, `method::<...>` | Specifies parameters to generic type, function, or method in an expression; often referred to as turbofish (e.g., `"42".parse::()`) | +| `path::<...>`, `method::<...>` | Specifies parameters to a generic type, function, or method in an expression; often referred to as turbofish (e.g., `"42".parse::()`) | | `fn ident<...> ...` | Define generic function | | `struct ident<...> ...` | Define generic structure | | `enum ident<...> ...` | Define generic enumeration | diff --git a/src/appendix-03-derivable-traits.md b/src/appendix-03-derivable-traits.md index 299796dbf7..3677281d75 100644 --- a/src/appendix-03-derivable-traits.md +++ b/src/appendix-03-derivable-traits.md @@ -21,7 +21,7 @@ for each trait for details of how to manually implement them. These traits listed here are the only ones defined by the standard library that can be implemented on your types using `derive`. Other traits defined in the standard library don’t have sensible default behavior, so it’s up to you to -implement them in the way that makes sense for what you’re trying to accomplish. +implement them in a way that makes sense for what you’re trying to accomplish. An example of a trait that can’t be derived is `Display`, which handles formatting for end users. You should always consider the appropriate way to @@ -45,7 +45,7 @@ The `Debug` trait allows you to print instances of a type for debugging purposes, so you and other programmers using your type can inspect an instance at a particular point in a program’s execution. -The `Debug` trait is required, for example, in use of the `assert_eq!` macro. +The `Debug` trait is required, for example, in using the `assert_eq!` macro. This macro prints the values of instances given as arguments if the equality assertion fails so programmers can see why the two instances weren’t equal. @@ -71,14 +71,14 @@ number types: the implementation of floating point numbers states that two instances of the not-a-number (`NaN`) value are not equal to each other. An example of when `Eq` is required is for keys in a `HashMap` so the -`HashMap` can tell whether two keys are the same. +`HashMap` can tell whether two keys are identical. ### `PartialOrd` and `Ord` for Ordering Comparisons The `PartialOrd` trait allows you to compare instances of a type for sorting purposes. A type that implements `PartialOrd` can be used with the `<`, `>`, `<=`, and `>=` operators. You can only apply the `PartialOrd` trait to types -that also implement `PartialEq`. +that implement `PartialEq`. Deriving `PartialOrd` implements the `partial_cmp` method, which returns an `Option` that will be `None` when the values given don’t produce an @@ -115,7 +115,7 @@ data. See the [“Ways Variables and Data Interact: Clone”][ways-variables-and-data-interact-clone] section in Chapter 4 for more information on `Clone`. -Deriving `Clone` implements the `clone` method, which when implemented for the +Deriving `Clone` implements the `clone` method, which, when implemented for the whole type, calls `clone` on each of the parts of the type. This means all the fields or values in the type must also implement `Clone` to derive `Clone`. diff --git a/src/appendix-04-useful-development-tools.md b/src/appendix-04-useful-development-tools.md index 40b076153d..b36ab7d950 100644 --- a/src/appendix-04-useful-development-tools.md +++ b/src/appendix-04-useful-development-tools.md @@ -1,6 +1,6 @@ ## Appendix D - Useful Development Tools -In this appendix, we talk about some useful development tools that the Rust +In this appendix, we talk about some useful development tools the Rust project provides. We’ll look at automatic formatting, quick ways to apply warning fixes, a linter, and integrating with IDEs. @@ -32,8 +32,7 @@ on `rustfmt`, see [its documentation][rustfmt]. ### Fix Your Code with `rustfix` The rustfix tool is included with Rust installations and can automatically fix -compiler warnings that have a clear way to correct the problem that’s likely -what you want. It’s likely you’ve seen compiler warnings before. For example, +compiler warnings that have a clear way to correct the problem in a way you likely want. It’s likely you’ve seen compiler warnings before. For example, consider this code: Filename: src/main.rs @@ -66,7 +65,7 @@ warning: unused variable: `i` ``` The warning suggests that we use `_i` as a name instead: the underscore -indicates that we intend for this variable to be unused. We can automatically +indicates that we intend this variable to be unused. We can automatically apply that suggestion using the `rustfix` tool by running the command `cargo fix`: @@ -138,7 +137,7 @@ error: approximate value of `f{32, 64}::consts::PI` found | = note: `#[deny(clippy::approx_constant)]` on by default = help: consider using the constant directly - = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#approx_constant + = help: for further information, visit https://rust-lang.github.io/rust-clippy/master/index.html#approx_constant ``` This error lets you know that Rust already has a more precise `PI` constant diff --git a/src/appendix-05-editions.md b/src/appendix-05-editions.md index 90828ebbaf..65ac46c554 100644 --- a/src/appendix-05-editions.md +++ b/src/appendix-05-editions.md @@ -43,9 +43,9 @@ together. Edition changes only affect the way the compiler initially parses code. Therefore, if you’re using Rust 2015 and one of your dependencies uses Rust 2018, your project will compile and be able to use that dependency. The opposite situation, where your project uses Rust 2018 and a dependency uses -Rust 2015, works as well. +Rust 2015 works as well. -To be clear: most features will be available on all editions. Developers using +To be clear, most features will be available in all editions. Developers using any Rust edition will continue to see improvements as new stable releases are made. However, in some cases, mainly when new keywords are added, some new features might only be available in later editions. You will need to switch diff --git a/src/appendix-07-nightly-rust.md b/src/appendix-07-nightly-rust.md index 46e619c815..ca72b19df5 100644 --- a/src/appendix-07-nightly-rust.md +++ b/src/appendix-07-nightly-rust.md @@ -35,8 +35,7 @@ assume that the Rust team is working on the release of Rust 1.5. That release happened in December of 2015, but it will provide us with realistic version numbers. A new feature is added to Rust: a new commit lands on the `master` branch. Each night, a new nightly version of Rust is produced. Every day is a -release day, and these releases are created by our release infrastructure -automatically. So as time passes, our releases look like this, once a night: +release day, and these releases are created automatically by our release infrastructure. So, as time passes, our releases look like this once a night: ```text nightly: * - - * - - * @@ -62,7 +61,7 @@ nightly: * - - * - - * - - * - - * beta: * ``` -Let’s say a regression is found. Good thing we had some time to test the beta +Let’s say a regression is found. It's a good thing we had some time to test the beta release before the regression snuck into a stable release! The fix is applied to `master`, so that nightly is fixed, and then the fix is backported to the `beta` branch, and a new release of beta is produced: @@ -106,7 +105,7 @@ release, you can know the date of the next one: it’s six weeks later. A nice aspect of having releases scheduled every six weeks is that the next train is coming soon. If a feature happens to miss a particular release, there’s no need to worry: another one is happening in a short time! This helps reduce pressure -to sneak possibly unpolished features in close to the release deadline. +to sneak possibly unpolished features close to the release deadline. Thanks to this process, you can always check out the next build of Rust and verify for yourself that it’s easy to upgrade to: if a beta release doesn’t @@ -176,7 +175,7 @@ have a lot of Rust projects! So how do you learn about these new features? Rust’s development model follows a *Request For Comments (RFC) process*. If you’d like an improvement in Rust, -you can write up a proposal, called an RFC. +you can write up a proposal called an RFC. Anyone can write RFCs to improve Rust, and the proposals are reviewed and discussed by the Rust team, which is comprised of many topic subteams. There’s diff --git a/src/ch00-00-introduction.md b/src/ch00-00-introduction.md index 536988cb19..deed58514b 100644 --- a/src/ch00-00-introduction.md +++ b/src/ch00-00-introduction.md @@ -46,7 +46,7 @@ productive while writing systems-level code. ### Students -Rust is for students and those who are interested in learning about systems +Rust is for students and those interested in learning about systems concepts. Using Rust, many people have learned about topics like operating systems development. The community is very welcoming and happy to answer student questions. Through efforts such as this book, the Rust teams want to @@ -59,7 +59,7 @@ Hundreds of companies, large and small, use Rust in production for a variety of tasks, including command line tools, web services, DevOps tooling, embedded devices, audio and video analysis and transcoding, cryptocurrencies, bioinformatics, search engines, Internet of Things applications, machine -learning, and even major parts of the Firefox web browser. +learning, and even significant parts of the Firefox web browser. ### Open Source Developers @@ -72,7 +72,7 @@ language. Rust is for people who crave speed and stability in a language. By speed, we mean both how quickly Rust code can run and the speed at which Rust lets you write programs. The Rust compiler’s checks ensure stability through feature -additions and refactoring. This is in contrast to the brittle legacy code in +additions and refactoring. This contrasts with the brittle legacy code in languages without these checks, which developers are often afraid to modify. By striving for zero-cost abstractions, higher-level features that compile to lower-level code as fast as code written manually, Rust endeavors to make safe @@ -88,14 +88,14 @@ Rust a try and see if its choices work for you. This book assumes that you’ve written code in another programming language but doesn’t make any assumptions about which one. We’ve tried to make the material -broadly accessible to those from a wide variety of programming backgrounds. We -don’t spend a lot of time talking about what programming *is* or how to think +broadly accessible to those from various programming backgrounds. We +don’t spend much time talking about what programming *is* or how to think about it. If you’re entirely new to programming, you would be better served by reading a book that specifically provides an introduction to programming. ## How to Use This Book -In general, this book assumes that you’re reading it in sequence from front to +Generally, this book assumes that you’re reading it in sequence from front to back. Later chapters build on concepts in earlier chapters, and earlier chapters might not delve into details on a particular topic but will revisit the topic in a later chapter. @@ -123,13 +123,13 @@ enums to make custom types in Rust. In Chapter 7, you’ll learn about Rust’s module system and about privacy rules for organizing your code and its public Application Programming Interface -(API). Chapter 8 discusses some common collection data structures that the +(API). Chapter 8 discusses common collection data structures the standard library provides, such as vectors, strings, and hash maps. Chapter 9 explores Rust’s error-handling philosophy and techniques. Chapter 10 digs into generics, traits, and lifetimes, which give you the power to define code that applies to multiple types. Chapter 11 is all about testing, -which even with Rust’s safety guarantees is necessary to ensure your program’s +which, even with Rust’s safety guarantees, is necessary to ensure your program’s logic is correct. In Chapter 12, we’ll build our own implementation of a subset of functionality from the `grep` command line tool that searches for text within files. For this, we’ll use many of the concepts we discussed in the @@ -142,11 +142,11 @@ Chapter 15 discusses smart pointers that the standard library provides and the traits that enable their functionality. In Chapter 16, we’ll walk through different models of concurrent programming -and talk about how Rust helps you to program in multiple threads fearlessly. +and talk about how Rust helps you program in multiple threads fearlessly. Chapter 17 looks at how Rust idioms compare to object-oriented programming principles you might be familiar with. -Chapter 18 is a reference on patterns and pattern matching, which are powerful +Chapter 18 references patterns and pattern matching, which are powerful ways of expressing ideas throughout Rust programs. Chapter 19 contains a smorgasbord of advanced topics of interest, including unsafe Rust, macros, and more about lifetimes, traits, types, functions, and closures. @@ -159,7 +159,7 @@ more reference-like format. Appendix A covers Rust’s keywords, Appendix B covers Rust’s operators and symbols, Appendix C covers derivable traits provided by the standard library, Appendix D covers some useful development tools, and Appendix E explains Rust editions. In Appendix F, you can find -translations of the book, and in Appendix G we’ll cover how Rust is made and +translations of the book, and in Appendix G, we’ll cover how Rust is made and what nightly Rust is. There is no wrong way to read this book: if you want to skip ahead, go for it! @@ -168,13 +168,13 @@ confusion. But do whatever works for you. -An important part of the process of learning Rust is learning how to read the +An important part of learning Rust is learning how to read the error messages the compiler displays: these will guide you toward working code. -As such, we’ll provide many examples that don’t compile along with the error +As such, we’ll provide many examples that don’t compile, along with the error message the compiler will show you in each situation. Know that if you enter and run a random example, it may not compile! Make sure you read the surrounding text to see whether the example you’re trying to run is meant to -error. Ferris will also help you distinguish code that isn’t meant to work: +be an error. Ferris will also help you distinguish code that isn’t meant to work: | Ferris | Meaning | |------------------------------------------------------------------------------------------------------------------|--------------------------------------------------| diff --git a/src/ch01-01-installation.md b/src/ch01-01-installation.md index 87f37fab26..ca0d6a8ee7 100644 --- a/src/ch01-01-installation.md +++ b/src/ch01-01-installation.md @@ -11,7 +11,7 @@ The following steps install the latest stable version of the Rust compiler. Rust’s stability guarantees ensure that all the examples in the book that compile will continue to compile with newer Rust versions. The output might differ slightly between versions because Rust often improves error messages and -warnings. In other words, any newer, stable version of Rust you install using +warnings. In other words, any more recent stable version of Rust you install using these steps should work as expected with the content of this book. > ### Command Line Notation @@ -39,7 +39,7 @@ for your password. If the install is successful, the following line will appear: Rust is installed now. Great! ``` -You will also need a *linker*, which is a program that Rust uses to join its +You will also need a *linker*, which is a program Rust uses to combine its compiled outputs into one file. It is likely you already have one. If you get linker errors, you should install a C compiler, which will typically include a linker. A C compiler is also useful because some common Rust packages depend on @@ -83,14 +83,14 @@ $ rustc --version ``` You should see the version number, commit hash, and commit date for the latest -stable version that has been released, in the following format: +stable version that has been released in the following format: ```text rustc x.y.z (abcabcabc yyyy-mm-dd) ``` If you see this information, you have installed Rust successfully! If you don’t -see this information, check that Rust is in your `%PATH%` system variable as +see this information and check that Rust is in your `%PATH%` system variable as follows. In Windows CMD, use: @@ -111,7 +111,7 @@ In Linux and macOS, use: $ echo $PATH ``` -If that’s all correct and Rust still isn’t working, there are a number of +If that’s all correct and Rust still isn’t working, there are several places you can get help. Find out how to get in touch with other Rustaceans (a silly nickname we call ourselves) on [the community page][community]. diff --git a/src/ch01-02-hello-world.md b/src/ch01-02-hello-world.md index f291463799..93af283ce4 100644 --- a/src/ch01-02-hello-world.md +++ b/src/ch01-02-hello-world.md @@ -102,11 +102,11 @@ first line declares a function named `main` that has no parameters and returns nothing. If there were parameters, they would go inside the parentheses `()`. The function body is wrapped in `{}`. Rust requires curly brackets around all -function bodies. It’s good style to place the opening curly bracket on the same +function bodies. It’s a good style to place the opening curly bracket on the same line as the function declaration, adding one space in between. > Note: If you want to stick to a standard style across Rust projects, you can -> use an automatic formatter tool called `rustfmt` to format your code in a +> use an automatic formatting tool called `rustfmt` to format your code in a > particular style (more on `rustfmt` in > [Appendix D][devtools]). The Rust team has included this tool > with the standard Rust distribution, as `rustc` is, so it should already be @@ -121,7 +121,7 @@ The body of the `main` function holds the following code: This line does all the work in this little program: it prints text to the screen. There are four important details to notice here. -First, Rust style is to indent with four spaces, not a tab. +First, the Rust style is to indent with four spaces, not a tab. Second, `println!` calls a Rust macro. If it had called a function instead, it would be entered as `println` (without the `!`). We’ll discuss Rust macros in @@ -161,7 +161,7 @@ main main.rs ``` On Linux and macOS, you’ll see two files. With PowerShell on Windows, you’ll -see the same three files that you would see using CMD. With CMD on Windows, you +see the same three files you would see using CMD. With CMD on Windows, you would enter the following: ```cmd