@@ -32,21 +32,21 @@ Linux or a Mac, all you need to do is this (note that you don't need to type
32
32
in the ` $ ` s, they just indicate the start of each command):
33
33
34
34
``` {ignore}
35
- $ curl -s http ://www .rust-lang.org/rustup.sh | sudo sh
35
+ $ curl -s https ://static .rust-lang.org/rustup.sh | sudo sh
36
36
```
37
37
38
38
(If you're concerned about ` curl | sudo sh ` , please keep reading. Disclaimer
39
39
below.)
40
40
41
41
If you're on Windows, please [ download this .exe and run
42
- it] ( http ://static.rust-lang.org/dist/rust-nightly-install.exe) .
42
+ it] ( https ://static.rust-lang.org/dist/rust-nightly-install.exe) .
43
43
44
44
If you decide you don't want Rust anymore, we'll be a bit sad, but that's okay.
45
45
Not every programming language is great for everyone. Just pass an argument to
46
46
the script:
47
47
48
48
``` {ignore}
49
- $ curl -s http ://www .rust-lang.org/rustup.sh | sudo sh -s -- --uninstall
49
+ $ curl -s https ://static .rust-lang.org/rustup.sh | sudo sh -s -- --uninstall
50
50
```
51
51
52
52
If you used the Windows installer, just re-run the ` .exe ` and it will give you
@@ -1341,7 +1341,7 @@ computer science: naming things, cache invalidation, and off-by-one errors."
1341
1341
The joke, of course, being that the setup says "two hard problems" but then
1342
1342
lists three things. This happens quite a bit with "C style" ` for ` loops.
1343
1343
1344
- We'll talk more about ` for ` when we cover ** iterator ** s, later in the Guide.
1344
+ We'll talk more about ` for ` when we cover ** vector ** s, later in the Guide.
1345
1345
1346
1346
## ` while `
1347
1347
@@ -1427,6 +1427,11 @@ for x in range(0i, 10i) {
1427
1427
1428
1428
Both ` continue ` and ` break ` are valid in both kinds of loops.
1429
1429
1430
+ We have now learned all of the most basic Rust concepts. We're ready to start
1431
+ building our guessing game, but we need to know how to do one last thing first:
1432
+ get input from the keyboard. You can't have a guessing game without the ability
1433
+ to guess!
1434
+
1430
1435
# Strings
1431
1436
1432
1437
Strings are an important concept for any programmer to master. Rust's string
@@ -1507,76 +1512,6 @@ low-level details matter, they really matter. Just remember that `String`s
1507
1512
allocate memory and control their data, while ` &str ` s are a reference to
1508
1513
another string, and you'll be all set.
1509
1514
1510
- # Vectors
1511
-
1512
- Like many programming languages, Rust has a list type for when you want a list
1513
- of things. But similar to strings, Rust has different types to represent this
1514
- idea: ` Vec<T> ` (a 'vector'), ` [T, .. N] ` (an 'array'), and ` &[T] ` (a 'slice').
1515
- Whew!
1516
-
1517
- Vectors are similar to ` String ` s: they have a dynamic length, and they
1518
- allocate enough memory to fit. You can create a vector with the ` vec! ` macro:
1519
-
1520
- ``` {rust}
1521
- let nums = vec![1i, 2i, 3i];
1522
- ```
1523
-
1524
- Notice that unlike the ` println! ` macro we've used in the past, we use square
1525
- brackets (` [] ` ) with ` vec! ` . Rust allows you to use either in either situation,
1526
- this is just convention.
1527
-
1528
- You can create an array with just square brackets:
1529
-
1530
- ``` {rust}
1531
- let nums = [1i, 2i, 3i];
1532
- ```
1533
-
1534
- So what's the difference? An array has a fixed size, so you can't add or
1535
- subtract elements:
1536
-
1537
- ``` {rust,ignore}
1538
- let mut nums = vec![1i, 2i, 3i];
1539
- nums.push(4i); // works
1540
-
1541
- let mut nums = [1i, 2i, 3i];
1542
- nums.push(4i); // error: type `[int, .. 3]` does not implement any method
1543
- // in scope named `push`
1544
- ```
1545
-
1546
- The ` push() ` method lets you append a value to the end of the vector. But
1547
- since arrays have fixed sizes, adding an element doesn't make any sense.
1548
- You can see how it has the exact type in the error message: ` [int, .. 3] ` .
1549
- An array of ` int ` s, with length 3.
1550
-
1551
- Similar to ` &str ` , a slice is a reference to another array. We can get a
1552
- slice from a vector by using the ` as_slice() ` method:
1553
-
1554
- ``` {rust}
1555
- let vec = vec![1i, 2i, 3i];
1556
- let slice = vec.as_slice();
1557
- ```
1558
-
1559
- All three types implement an ` iter() ` method, which returns an iterator. We'll
1560
- talk more about the details of iterators later, but for now, the ` iter() ` method
1561
- allows you to write a ` for ` loop that prints out the contents of a vector, array,
1562
- or slice:
1563
-
1564
- ``` {rust}
1565
- let vec = vec![1i, 2i, 3i];
1566
-
1567
- for i in vec.iter() {
1568
- println!("{}", i);
1569
- }
1570
- ```
1571
-
1572
- This code will print each number in order, on its own line.
1573
-
1574
- There's a whole lot more to vectors, but that's enough to get started. We have
1575
- now learned all of the most basic Rust concepts. We're ready to start building
1576
- our guessing game, but we need to know how to do one last thing first: get
1577
- input from the keyboard. You can't have a guessing game without the ability to
1578
- guess!
1579
-
1580
1515
# Standard Input
1581
1516
1582
1517
Getting input from the keyboard is pretty easy, but uses some things
0 commit comments