@@ -32,7 +32,7 @@ warnings. In other words, any newer, stable version of Rust you install using
3232these steps should work as expected with the content of this book.
3333
3434> ### Command Line Notation
35- >
35+ >
3636> In this chapter and throughout the book, we’ll show some commands used in the
3737> terminal. Lines that you should enter in a terminal all start with ` $ ` . You
3838> don’t need to type the ` $ ` character; it’s the command line prompt shown to
@@ -74,11 +74,11 @@ the `build-essential` package.
7474
7575### Installing rustup on Windows
7676
77- On Windows, go to https://www.rust-lang.org/tools/install at * https://www.rust-lang.org/tools/install * and follow
78- the instructions for installing Rust. At some point in the installation, you’ll
79- be prompted to install Visual Studio. This provides a linker and the native
80- libraries needed to compile programs. If you need more help with this step, see
81- https://rust-lang.github.io/rustup/installation/windows-msvc.html at * https://rust-lang.github.io/rustup/installation/windows-msvc.html *
77+ On Windows, go to https://www.rust-lang.org/tools/install and follow the instructions for installing Rust. At some point in the
78+ installation, you’ll be prompted to install Visual Studio. This provides a
79+ linker and the native libraries needed to compile programs. If you need more
80+ help with this step, see
81+ https://rust-lang.github.io/rustup/installation/windows-msvc.html .
8282
8383The rest of this book uses commands that work in both * cmd.exe* and PowerShell.
8484If there are specific differences, we’ll explain which to use.
@@ -141,7 +141,11 @@ shell:
141141$ rustup self uninstall
142142```
143143
144- ### Local Documentation
144+ <!-- Old headings. Do not remove or links may break. -->
145+
146+ <a id =" local-documentation " ></a >
147+
148+ ### Reading the Local Documentation
145149
146150The installation of Rust also includes a local copy of the documentation so
147151that you can read it offline. Run ` rustup doc ` to open the local documentation
@@ -151,7 +155,11 @@ Any time a type or function is provided by the standard library and you’re not
151155sure what it does or how to use it, use the application programming interface
152156(API) documentation to find out!
153157
154- ### Text Editors and Integrated Development Environments
158+ <!-- Old headings. Do not remove or links may break. -->
159+
160+ <a id =" text-editors-and-integrated-development-environments " ></a >
161+
162+ ### Using Text Editors and IDEs
155163
156164This book makes no assumptions about what tools you use to author Rust code.
157165Just about any text editor will get the job done! However, many text editors and
@@ -167,13 +175,17 @@ prints the text `Hello, world!` to the screen, so we’ll do the same here!
167175
168176> Note: This book assumes basic familiarity with the command line. Rust makes
169177> no specific demands about your editing or tooling or where your code lives, so
170- > if you prefer to use an integrated development environment (IDE) instead of
171- > the command line, feel free to use your favorite IDE. Many IDEs now have some
172- > degree of Rust support; check the IDE’s documentation for details. The Rust
173- > team has been focusing on enabling great IDE support via ` rust-analyzer ` . See
174- > Appendix D for more details.
178+ > if you prefer to use an IDE instead of the command line, feel free to use your
179+ > favorite IDE. Many IDEs now have some degree of Rust support; check the IDE’s
180+ > documentation for details. The Rust team has been focusing on enabling great
181+ > IDE support via ` rust-analyzer ` . See Appendix D
182+ > for more details.
183+
184+ <!-- Old headings. Do not remove or links may break. -->
185+
186+ <a id =" creating-a-project-directory " ></a >
175187
176- ### Creating a Project Directory
188+ ### Project Directory Setup
177189
178190You’ll start by making a directory to store your Rust code. It doesn’t matter
179191to Rust where your code lives, but for the exercises and projects in this book,
@@ -201,7 +213,11 @@ For Windows CMD, enter this:
201213> cd hello_world
202214```
203215
204- ### Writing and Running a Rust Program
216+ <!-- Old headings. Do not remove or links may break. -->
217+
218+ <a id =" writing-and-running-a-rust-program " ></a >
219+
220+ ### Rust Program Basics
205221
206222Next, make a new source file and call it * main.rs* . Rust files always end with
207223the * .rs* extension. If you’re using more than one word in your filename, the
@@ -257,10 +273,10 @@ fn main() {
257273}
258274```
259275
260- These lines define a function named ` main ` . The ` main ` function is special: it
276+ These lines define a function named ` main ` . The ` main ` function is special: It
261277is always the first code that runs in every executable Rust program. Here, the
262278first line declares a function named ` main ` that has no parameters and returns
263- nothing. If there were parameters, they would go inside the parentheses ` () ` .
279+ nothing. If there were parameters, they would go inside the parentheses ( ` () ` ) .
264280
265281The function body is wrapped in ` {} ` . Rust requires curly brackets around all
266282function bodies. It’s good style to place the opening curly bracket on the same
@@ -279,24 +295,28 @@ The body of the `main` function holds the following code:
279295println!("Hello, world!");
280296```
281297
282- This line does all the work in this little program: it prints text to the
298+ This line does all the work in this little program: It prints text to the
283299screen. There are three important details to notice here.
284300
285301First, ` println! ` calls a Rust macro. If it had called a function instead, it
286302would be entered as ` println ` (without the ` ! ` ). Rust macros are a way to write
287303code that generates code to extend Rust syntax, and we’ll discuss them in more
288- detail in Chapter 20. For now, you just need to know that using a ` ! ` means
289- that you’re calling a macro instead of a normal function and that macros don’t
290- always follow the same rules as functions.
304+ detail in Chapter 20. For now, you just need to
305+ know that using a ` ! ` means that you’re calling a macro instead of a normal
306+ function and that macros don’t always follow the same rules as functions.
291307
292308Second, you see the ` "Hello, world!" ` string. We pass this string as an argument
293309to ` println! ` , and the string is printed to the screen.
294310
295311Third, we end the line with a semicolon (` ; ` ), which indicates that this
296- expression is over and the next one is ready to begin. Most lines of Rust code
312+ expression is over, and the next one is ready to begin. Most lines of Rust code
297313end with a semicolon.
298314
299- ### Compiling and Running Are Separate Steps
315+ <!-- Old headings. Do not remove or links may break. -->
316+
317+ <a id =" compiling-and-running-are-separate-steps " ></a >
318+
319+ ### Compilation and Execution
300320
301321You’ve just run a newly created program, so let’s examine each step in the
302322process.
@@ -456,7 +476,7 @@ fn main() {
456476
457477Cargo has generated a “Hello, world!” program for you, just like the one we
458478wrote in Listing 1-1! So far, the differences between our project and the
459- project Cargo generated are that Cargo placed the code in the * src* directory
479+ project Cargo generated are that Cargo placed the code in the * src* directory,
460480and we have a * Cargo.toml* configuration file in the top directory.
461481
462482Cargo expects your source files to live inside the * src* directory. The
@@ -540,7 +560,7 @@ Why would you not want an executable? Often, `cargo check` is much faster than
540560continually checking your work while writing the code, using ` cargo check ` will
541561speed up the process of letting you know if your project is still compiling! As
542562such, many Rustaceans run ` cargo check ` periodically as they write their
543- program to make sure it compiles. Then they run ` cargo build ` when they’re
563+ program to make sure it compiles. Then, they run ` cargo build ` when they’re
544564ready to use the executable.
545565
546566Let’s recap what we’ve learned so far about Cargo:
@@ -569,7 +589,11 @@ repeatedly and that will run as fast as possible. If you’re benchmarking your
569589code’s running time, be sure to run ` cargo build --release ` and benchmark with
570590the executable in * target/release* .
571591
572- ### Cargo as Convention
592+ <!-- Old headings. Do not remove or links may break. -->
593+
594+ <a id =" cargo-as-convention " ></a >
595+
596+ ### Leveraging Cargo’s Conventions
573597
574598With simple projects, Cargo doesn’t provide a lot of value over just using
575599` rustc ` , but it will prove its worth as your programs become more intricate.
@@ -591,14 +615,14 @@ For more information about Cargo, check out its documentation at *https://doc.ru
591615
592616## Summary
593617
594- You’re already off to a great start on your Rust journey! In this chapter,
595- you’ve learned how to:
618+ You’re already off to a great start on your Rust journey! In this chapter, you
619+ learned how to:
596620
597- * Install the latest stable version of Rust using ` rustup `
598- * Update to a newer Rust version
599- * Open locally installed documentation
600- * Write and run a “Hello, world!” program using ` rustc ` directly
601- * Create and run a new project using the conventions of Cargo
621+ * Install the latest stable version of Rust using ` rustup ` .
622+ * Update to a newer Rust version.
623+ * Open locally installed documentation.
624+ * Write and run a “Hello, world!” program using ` rustc ` directly.
625+ * Create and run a new project using the conventions of Cargo.
602626
603627This is a great time to build a more substantial program to get used to reading
604628and writing Rust code. So, in Chapter 2, we’ll build a guessing game program.
0 commit comments