diff --git a/src/ch01-01-installation.md b/src/ch01-01-installation.md index 47664eb4f..fa9617ad9 100644 --- a/src/ch01-01-installation.md +++ b/src/ch01-01-installation.md @@ -10,18 +10,18 @@ an internet connection for the download. 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 these steps should work as expected with the content of this book. +differ slightly between versions because Rust often improves error messages and +warnings. In other words, any newer, stable version of Rust you install using +these steps should work as expected with the content of this book. > ### Command Line Notation > > In this chapter and throughout the book, we’ll show some commands used in the > terminal. Lines that you should enter in a terminal all start with `$`. You -> don’t need to type in the `$` character; it’s the command line prompt shown -> to indicate the start of each command. Lines that don’t start with `$` -> typically show the output of the previous command. Additionally, -> PowerShell-specific examples will use `>` rather than `$`. +> don’t need to type the `$` character; it’s the command line prompt shown to +> indicate the start of each command. Lines that don’t start with `$` typically +> show the output of the previous command. Additionally, PowerShell-specific +> examples will use `>` rather than `$`. ### Installing `rustup` on Linux or macOS @@ -60,13 +60,14 @@ the `build-essential` package. On Windows, go to [https://www.rust-lang.org/tools/install][install] and follow the instructions for installing Rust. At some point in the installation, you’ll receive a message explaining that you’ll also need the MSVC build tools for -Visual Studio 2013 or later. To acquire the build tools, you’ll need to install -[Visual Studio 2022][visualstudio]. When asked which workloads to install, -include: +Visual Studio 2013 or later. -- “Desktop Development with C++” -- The Windows 10 or 11 SDK -- The English language pack component, along with any other language pack of +To acquire the build tools, you’ll need to install [Visual Studio +2022][visualstudio]. When asked which workloads to install, include: + +* “Desktop Development with C++” +* The Windows 10 or 11 SDK +* The English language pack component, along with any other language pack of your choosing The rest of this book uses commands that work in both *cmd.exe* and PowerShell. @@ -82,15 +83,15 @@ $ 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 follows. +see this information, check that Rust is in your `%PATH%` system variable as +follows. In Windows CMD, use: @@ -100,27 +101,24 @@ In Windows CMD, use: In PowerShell, use: -```console +```powershell > echo $env:Path ``` In Linux and macOS, use: ```console -echo $PATH +$ echo $PATH ``` If that’s all correct and Rust still isn’t working, there are a number of -places you can get help. The easiest is the #beginners channel on [the official -Rust Discord][discord]. There, you can chat with other Rustaceans (a silly -nickname we call ourselves) who can help you out. Other great resources include -[the Users forum][users] and [Stack Overflow][stackoverflow]. +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]. ### Updating and Uninstalling -Once Rust is installed via `rustup`, when a new version of Rust is released, -updating to the latest version is easy. From your shell, run the following -update script: +Once Rust is installed via `rustup`, updating to a newly released version is +easy. From your shell, run the following update script: ```console $ rustup update @@ -135,9 +133,9 @@ $ rustup self uninstall ### Local Documentation -The installation of Rust also includes a local copy of the documentation, so -you can read it offline. Run `rustup doc` to open the local documentation in -your browser. +The installation of Rust also includes a local copy of the documentation so +that you can read it offline. Run `rustup doc` to open the local documentation +in your browser. Any time a type or function is provided by the standard library and you’re not sure what it does or how to use it, use the application programming interface @@ -146,6 +144,4 @@ sure what it does or how to use it, use the application programming interface [otherinstall]: https://forge.rust-lang.org/infra/other-installation-methods.html [install]: https://www.rust-lang.org/tools/install [visualstudio]: https://visualstudio.microsoft.com/downloads/ -[discord]: https://discord.gg/rust-lang -[users]: https://users.rust-lang.org/ -[stackoverflow]: https://stackoverflow.com/questions/tagged/rust +[community]: https://www.rust-lang.org/community diff --git a/src/ch01-02-hello-world.md b/src/ch01-02-hello-world.md index ce9b8f55b..8d8d754d7 100644 --- a/src/ch01-02-hello-world.md +++ b/src/ch01-02-hello-world.md @@ -1,8 +1,8 @@ ## Hello, World! -Now that you’ve installed Rust, let’s write your first Rust program. It’s -traditional when learning a new language to write a little program that prints -the text `Hello, world!` to the screen, so we’ll do the same here! +Now that you’ve installed Rust, it’s time to write your first Rust program. +It’s traditional when learning a new language to write a little program that +prints the text `Hello, world!` to the screen, so we’ll do the same here! > Note: This book assumes basic familiarity with the command line. Rust makes > no specific demands about your editing or tooling or where your code lives, so @@ -10,7 +10,7 @@ the text `Hello, world!` to the screen, so we’ll do the same here! > the command line, feel free to use your favorite IDE. Many IDEs now have some > degree of Rust support; check the IDE’s documentation for details. The Rust > team has been focusing on enabling great IDE support via `rust-analyzer`. See -> [Appendix D][devtools] for more details! +> [Appendix D][devtools] for more details. ### Creating a Project Directory @@ -109,7 +109,7 @@ line as the function declaration, adding one space in between. > use an automatic formatter 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, like `rustc`, so it should already be +> with the standard Rust distribution, as `rustc` is, so it should already be > installed on your computer! The body of the `main` function holds the following code: @@ -126,7 +126,7 @@ First, 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 more detail in Chapter 19. For now, you just need to know that using a `!` -means that you’re calling a macro instead of a normal function, and that macros +means that you’re calling a macro instead of a normal function and that macros don’t always follow the same rules as functions. Third, you see the `"Hello, world!"` string. We pass this string as an argument @@ -153,16 +153,16 @@ If you have a C or C++ background, you’ll notice that this is similar to `gcc` or `clang`. After compiling successfully, Rust outputs a binary executable. On Linux, macOS, and PowerShell on Windows, you can see the executable by -entering the `ls` command in your shell. 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. +entering the `ls` command in your shell: ```console $ ls main main.rs ``` -With CMD on Windows, you would enter the following: +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 +would enter the following: ```cmd > dir /B %= the /B option says to only show the file names =% diff --git a/src/ch01-03-hello-cargo.md b/src/ch01-03-hello-cargo.md index 9979e76dd..42cd0889c 100644 --- a/src/ch01-03-hello-cargo.md +++ b/src/ch01-03-hello-cargo.md @@ -17,7 +17,7 @@ assumes that you’re using Cargo too. Cargo comes installed with Rust if you used the official installers discussed in the [“Installation”][installation] section. If you installed Rust through some other means, check whether Cargo is installed by entering the -following into your terminal: +following in your terminal: ```console $ cargo --version @@ -30,9 +30,9 @@ determine how to install Cargo separately. ### Creating a Project with Cargo Let’s create a new project using Cargo and look at how it differs from our -original “Hello, world!” project. Navigate back to your *projects* directory (or -wherever you decided to store your code). Then, on any operating system, run -the following: +original “Hello, world!” project. Navigate back to your *projects* directory +(or wherever you decided to store your code). Then, on any operating system, +run the following: ```console $ cargo new hello_cargo @@ -74,8 +74,8 @@ edition = "2021" Listing 1-2: Contents of *Cargo.toml* generated by `cargo new` -This file is in the [*TOML*](https://toml.io) (*Tom’s Obvious, -Minimal Language*) format, which is Cargo’s configuration format. +This file is in the [*TOML*][toml] (*Tom’s Obvious, Minimal +Language*) format, which is Cargo’s configuration format. The first line, `[package]`, is a section heading that indicates that the following statements are configuring a package. As we add more information to @@ -102,7 +102,7 @@ fn main() { Cargo has generated a “Hello, world!” program for you, just like the one we wrote in Listing 1-1! So far, the differences between our project and the -project Cargo generated are that Cargo placed the code in the *src* directory, +project Cargo generated are that Cargo placed the code in the *src* directory and we have a *Cargo.toml* configuration file in the top directory. Cargo expects your source files to live inside the *src* directory. The @@ -147,7 +147,7 @@ manages its contents for you. We just built a project with `cargo build` and ran it with `./target/debug/hello_cargo`, but we can also use `cargo run` to compile the -code and then run the resulting executable all in one command: +code and then run the resultant executable all in one command: ```console $ cargo run @@ -184,7 +184,7 @@ $ cargo check ``` Why would you not want an executable? Often, `cargo check` is much faster than -`cargo build`, because it skips the step of producing an executable. If you’re +`cargo build` because it skips the step of producing an executable. If you’re continually checking your work while writing the code, using `cargo check` will speed up the process of letting you know if your project is still compiling! As such, many Rustaceans run `cargo check` periodically as they write their @@ -236,9 +236,7 @@ $ cd someproject $ cargo build ``` -For more information about Cargo, check out [its documentation]. - -[its documentation]: https://doc.rust-lang.org/cargo/ +For more information about Cargo, check out [its documentation][cargo]. ## Summary @@ -257,4 +255,6 @@ If you would rather start by learning how common programming concepts work in Rust, see Chapter 3 and then return to Chapter 2. [installation]: ch01-01-installation.html#installation +[toml]: https://toml.io [appendix-e]: appendix-05-editions.html +[cargo]: https://doc.rust-lang.org/cargo/