From a189fbb0d08fa5c19a202b4db76ecb24cd88f116 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Mon, 21 Dec 2015 17:58:55 +0000 Subject: [PATCH] rebuild pages at 2c42421 --- primitive-rust.html | 13 ++++++----- print.html | 50 +++++++++++++++++++++++------------------- variable-bindings.html | 37 +++++++++++++++++-------------- 3 files changed, 56 insertions(+), 44 deletions(-) diff --git a/primitive-rust.html b/primitive-rust.html index 4e4f5fb95..a78909f46 100644 --- a/primitive-rust.html +++ b/primitive-rust.html @@ -66,11 +66,14 @@

Primitive Rust

-

We’ll start our journey with Rust by talking about the absolute basics. -Many programming languages have lots in common at their core. -Much of this may feel similar to other languages you’ve used, but some parts are different. -If you want to skip this section, you can, but you may end up coming back later to find out small details. -These foundations will be in every single useful Rust program, and learning them gives us a strong core to start from.

+

We’ll start our journey with Rust by talking about the absolute basics — +concepts that appear in almost every programming language. Many programming +languages have lots in common at their core. None of the concepts presented are +unique to Rust, but we’ll cover Rust’s particular syntax and conventions around +these common concepts.

+

If you want to skip this section, you can, but you may end up coming back later +to find out small details. These foundations will be in every single useful +Rust program, and learning them gives us a strong core to start from.

diff --git a/print.html b/print.html index abfc0242b..aeccaa293 100644 --- a/print.html +++ b/print.html @@ -430,11 +430,14 @@ guide, which covers all of its features.

The Design of Rust

Tutorial

Primitive Rust

-

We’ll start our journey with Rust by talking about the absolute basics. -Many programming languages have lots in common at their core. -Much of this may feel similar to other languages you’ve used, but some parts are different. -If you want to skip this section, you can, but you may end up coming back later to find out small details. -These foundations will be in every single useful Rust program, and learning them gives us a strong core to start from.

+

We’ll start our journey with Rust by talking about the absolute basics — +concepts that appear in almost every programming language. Many programming +languages have lots in common at their core. None of the concepts presented are +unique to Rust, but we’ll cover Rust’s particular syntax and conventions around +these common concepts.

+

If you want to skip this section, you can, but you may end up coming back later +to find out small details. These foundations will be in every single useful +Rust program, and learning them gives us a strong core to start from.

Variable Bindings

The foundation of virtually every program is the ability to store and modify data. Rust programs are no different. @@ -474,18 +477,19 @@ We’ll talk more about functions in the next section, but for now, all we need The opening curly brace, {, indicates the start of the function’s body.

    let x = 5;
 
-

This is our first ‘variable binding’. -This looks like many languages, but there are some subtleties. -We create variable bindings with a ‘let statement’, which looks like this:

-
let PATTERN = VALUE;
+

This is our first ‘variable binding’, which we create with a ‘let statement’.

+

This let statement has this form:

+
let NAME = EXPRESSION;
 
-

In our example, the PATTERN is a humble x, and the VALUE is a simple 5. -The let statement takes the VALUE, and matches it to the PATTERN, creating new bindings. -Therefore, our example creates a new binding, x, and gives it an initial value of 5. -Patterns are a big part of Rust, we will see them in many places.

-

That seems like a lot of explanation for a basic assignment statement! -The trick is that these patterns can become more complex, and have a lot of power. -We’ll explore more complex patterns as we learn more.

+

A let statement first evaluates the EXPRESSION, and then binds the +resulting value to NAME so that it can be referred to later in the program. In +our simple example, the expression was already a value, 5, but we could achieve +the same effect with:

+
let x = 2 + 3;
+
+

In general, let statements work with patterns; a name is a particularly +humble form of pattern. Patterns are a big part of Rust, we’ll see more complex +and powerful patterns as we go along.

Before we do that, though, let’s finish investigating this example. Here’s the next line:

    println!("The value of x is: {}", x);
@@ -496,11 +500,13 @@ We won’t learn how to write macros until much later in the book, but we’ll u
 Every time you see a !, remember that it signifies a macro.
 Macros can add new syntax to the language, and the ! is a reminder that things may look slightly unusual.

println!, specifically, has one required argument, a ‘format string’, and zero or more optional arguments. -This is why it’s a macro; Rust does not support optional arguments for regular functions. The format string can contain the special text {}. -If it does, it fills in that place in the string with the values of the other arguments. -In this case, we’ve passed x. -You can think of {} as little crab pincers, holding the value in place. +Each instance of {} corresponds to an additional argument. Here’s an example:

+
let x = 2 + 3;
+let y = x + 5;
+println!("The value of x is {}, and the value of y is {}", x, y);
+
+

You can think of {} as little crab pincers, holding the value in place. This placeholder has a number of more advanced formatting options that we’ll discuss later.

}
 
@@ -509,7 +515,7 @@ This placeholder has a number of more advanced formatting options that we’ll d
The value of x is: 5
 

We assign 5 to a binding, x, and then print it to the screen with println!.

-

Multiple assignment

+

Multiple binding

Let’s try a more complex pattern. Change our example program to this:

fn main() {
@@ -572,7 +578,7 @@ As an example, here’s our more complex pattern with two bindings:

}

Just like we match up the VALUE with the PATTERN, we match up the TYPE with the PATTERN.

-

Initialization

+

Delayed Initialization

We do not have to provide bindings with an initial value, and can assign it later. Try this program:

fn main() {
     let x;
diff --git a/variable-bindings.html b/variable-bindings.html
index 4b616fd0a..897bc62bc 100644
--- a/variable-bindings.html
+++ b/variable-bindings.html
@@ -104,18 +104,19 @@ We’ll talk more about functions in the next section, but for now, all we need
 The opening curly brace, {, indicates the start of the function’s body.

    let x = 5;
 
-

This is our first ‘variable binding’. -This looks like many languages, but there are some subtleties. -We create variable bindings with a ‘let statement’, which looks like this:

-
let PATTERN = VALUE;
+

This is our first ‘variable binding’, which we create with a ‘let statement’.

+

This let statement has this form:

+
let NAME = EXPRESSION;
 
-

In our example, the PATTERN is a humble x, and the VALUE is a simple 5. -The let statement takes the VALUE, and matches it to the PATTERN, creating new bindings. -Therefore, our example creates a new binding, x, and gives it an initial value of 5. -Patterns are a big part of Rust, we will see them in many places.

-

That seems like a lot of explanation for a basic assignment statement! -The trick is that these patterns can become more complex, and have a lot of power. -We’ll explore more complex patterns as we learn more.

+

A let statement first evaluates the EXPRESSION, and then binds the +resulting value to NAME so that it can be referred to later in the program. In +our simple example, the expression was already a value, 5, but we could achieve +the same effect with:

+
let x = 2 + 3;
+
+

In general, let statements work with patterns; a name is a particularly +humble form of pattern. Patterns are a big part of Rust, we’ll see more complex +and powerful patterns as we go along.

Before we do that, though, let’s finish investigating this example. Here’s the next line:

    println!("The value of x is: {}", x);
@@ -126,11 +127,13 @@ We won’t learn how to write macros until much later in the book, but we’ll u
 Every time you see a !, remember that it signifies a macro.
 Macros can add new syntax to the language, and the ! is a reminder that things may look slightly unusual.

println!, specifically, has one required argument, a ‘format string’, and zero or more optional arguments. -This is why it’s a macro; Rust does not support optional arguments for regular functions. The format string can contain the special text {}. -If it does, it fills in that place in the string with the values of the other arguments. -In this case, we’ve passed x. -You can think of {} as little crab pincers, holding the value in place. +Each instance of {} corresponds to an additional argument. Here’s an example:

+
let x = 2 + 3;
+let y = x + 5;
+println!("The value of x is {}, and the value of y is {}", x, y);
+
+

You can think of {} as little crab pincers, holding the value in place. This placeholder has a number of more advanced formatting options that we’ll discuss later.

}
 
@@ -139,7 +142,7 @@ This placeholder has a number of more advanced formatting options that we’ll d
The value of x is: 5
 

We assign 5 to a binding, x, and then print it to the screen with println!.

-

Multiple assignment

+

Multiple binding

Let’s try a more complex pattern. Change our example program to this:

fn main() {
@@ -202,7 +205,7 @@ As an example, here’s our more complex pattern with two bindings:

}

Just like we match up the VALUE with the PATTERN, we match up the TYPE with the PATTERN.

-

Initialization

+

Delayed Initialization

We do not have to provide bindings with an initial value, and can assign it later. Try this program:

fn main() {
     let x;