Update chapter 1 from latest print edits

This commit is contained in:
Carol (Nichols || Goulding) 2022-09-13 13:53:09 -04:00 committed by Carol (Nichols || Goulding)
parent 16ba58d00d
commit f801008f55
3 changed files with 49 additions and 53 deletions

View File

@ -10,18 +10,18 @@ an internet connection for the download.
The following steps install the latest stable version of the Rust compiler.
Rusts 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, well show some commands used in the
> terminal. Lines that you should enter in a terminal all start with `$`. You
> dont need to type in the `$` character; its the command line prompt shown
> to indicate the start of each command. Lines that dont start with `$`
> typically show the output of the previous command. Additionally,
> PowerShell-specific examples will use `>` rather than `$`.
> dont need to type the `$` character; its the command line prompt shown to
> indicate the start of each command. Lines that dont 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, youll
receive a message explaining that youll also need the MSVC build tools for
Visual Studio 2013 or later. To acquire the build tools, youll 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, youll 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 dont
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 thats all correct and Rust still isnt 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 youre 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

View File

@ -1,8 +1,8 @@
## Hello, World!
Now that youve installed Rust, lets write your first Rust program. Its
traditional when learning a new language to write a little program that prints
the text `Hello, world!` to the screen, so well do the same here!
Now that youve installed Rust, its time to write your first Rust program.
Its traditional when learning a new language to write a little program that
prints the text `Hello, world!` to the screen, so well 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 well 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 IDEs documentation for details. The Rust
> team has been focusing on enabling great IDE support via `rust-analyzer`. See
> [Appendix D][devtools]<!-- ignore --> for more details!
> [Appendix D][devtools]<!-- ignore --> 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]<!-- ignore -->). 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 `!`). Well discuss Rust macros in
more detail in Chapter 19. For now, you just need to know that using a `!`
means that youre calling a macro instead of a normal function, and that macros
means that youre calling a macro instead of a normal function and that macros
dont 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, youll 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, youll see two
files. With PowerShell on Windows, youll 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, youll see two files. With PowerShell on Windows, youll
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 =%

View File

@ -17,7 +17,7 @@ assumes that youre using Cargo too. Cargo comes installed with Rust if you
used the official installers discussed in the
[“Installation”][installation]<!-- ignore --> 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
Lets 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"
<span class="caption">Listing 1-2: Contents of *Cargo.toml* generated by `cargo
new`</span>
This file is in the [*TOML*](https://toml.io)<!-- ignore --> (*Toms Obvious,
Minimal Language*) format, which is Cargos configuration format.
This file is in the [*TOML*][toml]<!-- ignore --> (*Toms Obvious, Minimal
Language*) format, which is Cargos 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 youre
`cargo build` because it skips the step of producing an executable. If youre
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/