From fdd28f7e66fa8d78bd248f90e5c69c2611bb8c7c Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Sun, 3 Jul 2016 15:15:21 -0400 Subject: [PATCH] Resolve comments in Anatomy of a Rust Program --- src/ch03-02-anatomy-of-a-rust-program.md | 97 ++++-------------------- 1 file changed, 16 insertions(+), 81 deletions(-) diff --git a/src/ch03-02-anatomy-of-a-rust-program.md b/src/ch03-02-anatomy-of-a-rust-program.md index ce63b45..a1d270d 100644 --- a/src/ch03-02-anatomy-of-a-rust-program.md +++ b/src/ch03-02-anatomy-of-a-rust-program.md @@ -7,13 +7,6 @@ variable, and how to print text to the terminal. ### Keywords - - First, keep in mind that the Rust language has a set of *keywords* that have been reserved for use by the language only. This means you cannot use these words as names of variables or functions, for example. Most of these have @@ -78,10 +71,10 @@ The keywords are: ### A Simple Program that Binds a Variable -Let’s start with a short example that binds a value to a variable, and then -uses that in a sentence that we'll print to the screen. First, we’ll generate a -new project with Cargo. Open a terminal, and navigate to the directory you want -to store your projects in. From there, generate a new project: +Let’s start with a short example that binds a value to a variable and then uses +that in a sentence that we'll print to the screen. First, we’ll generate a new +project with Cargo. Open a terminal, and navigate to the directory you want to +store your projects in. From there, generate a new project: ```bash $ cargo new --bin bindings @@ -124,33 +117,18 @@ down, line by line. #### Starting a Program with the main() Function -Most Rust programs open with the same first line as this one from our example -program: - +Many Rust programs will contain the same function that our example program does: ```rust,ignore fn main() { ``` -The `main()` function is the entry point of every Rust program. It doesn’t have -to be at the very beginning of our source code, but it will be the first bit of code that -runs when we execute our program. We’ll talk more about functions in the next -section, but for now, just know that ```main()``` is where our program begins. -The opening curly brace (`{`) indicates the start of the function’s body. +The `main()` function is the entry point of every executable Rust program. It +doesn’t have to be at the very beginning of our source code, but it will be the +first bit of code that runs when we execute our program. We’ll talk more about +functions in the next section, but for now, just know that `main()` is +where our program begins. The opening curly brace (`{`) indicates the start of +the function’s body. #### Binding a Variable with `let` @@ -167,10 +145,10 @@ Basic `let` statements take the following form: let NAME = EXPRESSION; ``` -A `let` statement first evaluates the `EXPRESSION`, and then binds the -resulting value to `NAME` to give us a variable to use later in the program. -Notice the semicolon at the end of the statement, too. As in many other -programming languages, statements in Rust must end with a semicolon. +A `let` statement first evaluates the `EXPRESSION` and then binds the resulting +value to `NAME` to give us a variable to use later in the program. Notice the +semicolon at the end of the statement, too. As in many other programming +languages, statements in Rust must end with a semicolon. In this simple example, the expression already is a value, but we could achieve the same result like this: @@ -194,37 +172,6 @@ expression that works on values in your program instead of characters in text. A name like `x` is a particularly humble form of pattern; it will always match and gets all the parts of the expression as its value. Patterns are a big part of Rust, and we’ll see more complex and powerful patterns as we go along. - #### Printing to the Screen with a Macro @@ -236,7 +183,7 @@ The next line of our program is: The `println!` command is a *macro* that prints the text passed to it to the screen. Macros are indicated with the `!` character at the end of their name. -In Chapter , you'll learn more about the details of macros and how to +In Chapter XX, you'll learn more about the details of macros and how to write macros yourself, but for now we'll just be using macros provided by the standard Rust library. @@ -250,18 +197,6 @@ generated for us called the `println!` macro with one argument (the string with the same number of arguments that their definition specifies, but macros have different rules that allow them to take different numbers of arguments. - - The `println!` macro only requires one argument: a format string. You can add optional arguments inside this format string by using the special text `{}`. Each instance of `{}` corresponds to an additional argument. Here’s an example: