@@ -7,7 +7,7 @@ displayed here in line with Rust's open development policy. Please open any
7
7
issues you find as usual.
8
8
</div >
9
9
10
- ## Welcome!
10
+ # Welcome!
11
11
12
12
Hey there! Welcome to the Rust guide. This is the place to be if you'd like to
13
13
learn how to program in Rust. Rust is a systems programming language with a
@@ -24,7 +24,7 @@ more advanced things.
24
24
25
25
Sound good? Let's go!
26
26
27
- ## Installing Rust
27
+ # Installing Rust
28
28
29
29
The first step to using Rust is to install it! There are a number of ways to
30
30
install Rust, but the easiest is to use the the ` rustup ` script. If you're on
@@ -106,7 +106,7 @@ mailing list](https://mail.mozilla.org/listinfo/rust-dev), [the /r/rust
106
106
subreddit] ( http://www.reddit.com/r/rust ) , and [ Stack
107
107
Overflow] ( http://stackoverflow.com/questions/tagged/rust ) .
108
108
109
- ## Hello, world!
109
+ # Hello, world!
110
110
111
111
Now that you have Rust installed, let's write your first Rust program. It's
112
112
traditional to make your first program in any new language one that prints the
@@ -266,7 +266,7 @@ your project grows, you'll want something to help you manage all of the options
266
266
that it has, and to make it easy to share your code with other people and
267
267
projects.
268
268
269
- ## Hello, Cargo!
269
+ # Hello, Cargo!
270
270
271
271
[ Cargo] ( http://crates.io ) is a tool that Rustaceans use to help manage their
272
272
Rust projects. Cargo is currently in an alpha state, just like Rust, and so it
@@ -362,7 +362,7 @@ Now that you've got the tools down, let's actually learn more about the Rust
362
362
language itself. These are the basics that will serve you well through the rest
363
363
of your time with Rust.
364
364
365
- ## Variable bindings
365
+ # Variable bindings
366
366
367
367
The first thing we'll learn about are 'variable bindings.' They look like this:
368
368
@@ -532,7 +532,7 @@ must initialize the binding before we use it? And how does it know that we have
532
532
or have not initialized the binding? For that, we need to learn our next
533
533
concept: ` if ` .
534
534
535
- ## If
535
+ # If
536
536
537
537
Rust's take on ` if ` is not particularly complex, but it's much more like the
538
538
` if ` you'll find in a dynamically typed language than in a more traditional
@@ -593,7 +593,7 @@ This reveals two interesting things about Rust: it is an expression-based
593
593
language, and semicolons are different than in other 'curly brace and
594
594
semicolon'-based languages. These two things are related.
595
595
596
- ### Expressions vs. Statements
596
+ ## Expressions vs. Statements
597
597
598
598
Rust is primarily an expression based language. There are only two kinds of
599
599
statements, and everything else is an expression.
@@ -681,7 +681,7 @@ unit instead.
681
681
There's one more time in which you won't see a semicolon at the end of a line
682
682
of Rust code. For that, we'll need our next concept: functions.
683
683
684
- ## Functions
684
+ # Functions
685
685
686
686
You've already seen one function so far, the ` main ` function:
687
687
@@ -829,7 +829,7 @@ There are some additional ways to define functions, but they involve features
829
829
that we haven't learned about yet, so let's just leave it at that for now.
830
830
831
831
832
- ## Comments
832
+ # Comments
833
833
834
834
Now that we have some functions, it's a good idea to learn about comments.
835
835
Comments are notes that you leave to other programmers to help explain things
@@ -877,13 +877,13 @@ You can use the `rustdoc` tool to generate HTML documentation from these doc
877
877
comments. We will talk more about ` rustdoc ` when we get to modules, as
878
878
generally, you want to export documentation for a full module.
879
879
880
- ## Compound Data Types
880
+ # Compound Data Types
881
881
882
882
Rust, like many programming languages, has a number of different data types
883
883
that are built-in. You've already done some simple work with integers and
884
884
strings, but next, let's talk about some more complicated ways of storing data.
885
885
886
- ### Tuples
886
+ ## Tuples
887
887
888
888
The first compound data type we're going to talk about are called ** tuple** s.
889
889
Tuples are an ordered list of a fixed size. Like this:
@@ -958,7 +958,7 @@ can destructure a pattern returned by a function, as well.
958
958
Tuples are a very simple data structure, and so are not often what you want.
959
959
Let's move on to their bigger sibling, structs.
960
960
961
- ### Structs
961
+ ## Structs
962
962
963
963
A struct is another form of a 'record type,' just like a tuple. There's a
964
964
difference: structs give each element that they contain a name, called a
@@ -1008,7 +1008,7 @@ fn main() {
1008
1008
1009
1009
This will print ` The point is at (5, 0) ` .
1010
1010
1011
- ### Tuple Structs and Newtypes
1011
+ ## Tuple Structs and Newtypes
1012
1012
1013
1013
Rust has another data type that's like a hybrid between a tuple and a struct,
1014
1014
called a ** tuple struct** . Tuple structs do have a name, but their fields
@@ -1064,7 +1064,7 @@ println!("length is {} inches", integer_length);
1064
1064
As you can see here, you can extract the inner integer type through a
1065
1065
destructuring ` let ` .
1066
1066
1067
- ### Enums
1067
+ ## Enums
1068
1068
1069
1069
Finally, Rust has a "sum type", an ** enum** . Enums are an incredibly useful
1070
1070
feature of Rust, and are used throughout the standard library. Enums look
@@ -1161,7 +1161,7 @@ useful when they're generic across types. But before we get to generics, let's
1161
1161
talk about how to fix this big ` if ` /` else ` statements we've been writing. We'll
1162
1162
do that with ` match ` .
1163
1163
1164
- ## Match
1164
+ # Match
1165
1165
1166
1166
Often, a simple ` if ` /` else ` isn't enough, because you have more than two
1167
1167
possible options. And ` else ` conditions can get incredibly complicated. So
@@ -1283,12 +1283,12 @@ fn main() {
1283
1283
In this case, it doesn't make a lot of sense, as we are just making a temporary
1284
1284
string where we don't need to, but sometimes, it's a nice pattern.
1285
1285
1286
- ## Looping
1286
+ # Looping
1287
1287
1288
1288
Looping is the last basic construct that we haven't learned yet in Rust. Rust has
1289
1289
two main looping constructs: ` for ` and ` while ` .
1290
1290
1291
- ### ` for `
1291
+ ## ` for `
1292
1292
1293
1293
The ` for ` loop is used to loop a particular number of times. Rust's ` for ` loops
1294
1294
work a bit differently than in other systems languages, however. Rust's ` for `
@@ -1337,7 +1337,7 @@ lists three things. This happens quite a bit with "C style" `for` loops.
1337
1337
1338
1338
We'll talk more about ` for ` when we cover ** vector** s, later in the Guide.
1339
1339
1340
- ### ` while `
1340
+ ## ` while `
1341
1341
1342
1342
The other kind of looping construct in Rust is the ` while ` loop. It looks like
1343
1343
this:
@@ -1375,7 +1375,7 @@ general, the more information we can give to the compiler, the better it
1375
1375
can do with safety and code generation. So you should always prefer
1376
1376
` loop ` when you plan to loop infinitely.
1377
1377
1378
- ### Ending iteration early
1378
+ ## Ending iteration early
1379
1379
1380
1380
Let's take a look at that ` while ` loop we had earlier:
1381
1381
@@ -1426,7 +1426,7 @@ building our guessing game, but we need to know how to do one last thing first:
1426
1426
get input from the keyboard. You can't have a guessing game without the ability
1427
1427
to guess!
1428
1428
1429
- ## Standard Input
1429
+ # Standard Input
1430
1430
1431
1431
Getting input from the keyboard is pretty easy, but uses some things
1432
1432
we haven't seen before. Here's a simple program that reads some input,
@@ -1586,7 +1586,7 @@ here.
1586
1586
That's all you need to get basic input from the standard input! It's not too
1587
1587
complicated, but there are a number of small parts.
1588
1588
1589
- ## Guessing Game
1589
+ # Guessing Game
1590
1590
1591
1591
Okay! We've got the basics of Rust down. Let's write a bigger program.
1592
1592
@@ -1597,7 +1597,7 @@ Upon entering our guess, it will tell us if we're too low or too high. Once we
1597
1597
guess correctly, it will congratulate us, and print the number of guesses we've
1598
1598
taken to the screen. Sound good?
1599
1599
1600
- ### Set up
1600
+ ## Set up
1601
1601
1602
1602
Let's set up a new project. Go to your projects directory, and make a new
1603
1603
directory for the project, as well as a ` src ` directory for our code:
@@ -1645,7 +1645,7 @@ Excellent! Open up your `src/guessing_game.rs` again. We'll be writing all of
1645
1645
our code in this file. We'll talk about multiple-file projects later on in the
1646
1646
guide.
1647
1647
1648
- ### Processing a Guess
1648
+ ## Processing a Guess
1649
1649
1650
1650
Let's get to it! The first thing we need to do for our guessing game is
1651
1651
allow our player to input a guess. Put this in your ` src/guessing_game.rs ` :
@@ -1674,7 +1674,7 @@ user to input a guess, get their input, and then print it out.
1674
1674
Because we talked about this in the section on standard I/O, I won't go into
1675
1675
more details here. If you need a refresher, go re-read that section.
1676
1676
1677
- ### Generating a secret number
1677
+ ## Generating a secret number
1678
1678
1679
1679
Next, we need to generate a secret number. To do that, we need to use Rust's
1680
1680
random number generation, which we haven't talked about yet. Rust includes a
@@ -1845,7 +1845,7 @@ You guessed: 3
1845
1845
1846
1846
Great! Next up: let's compare our guess to the secret guess.
1847
1847
1848
- ### Comparing guesses
1848
+ ## Comparing guesses
1849
1849
1850
1850
If you remember, earlier in the tutorial, we made a ` cmp ` function that compared
1851
1851
two numbers. Let's add that in, along with a ` match ` statement to compare the
@@ -2194,7 +2194,7 @@ the error messages help guide you towards the correct types.
2194
2194
Now we've got most of the game working, but we can only make one guess. Let's
2195
2195
change that by adding loops!
2196
2196
2197
- ### Looping
2197
+ ## Looping
2198
2198
2199
2199
As we already discussed, the ` loop ` key word gives us an infinite loop. So
2200
2200
let's add that in:
@@ -2455,7 +2455,7 @@ fn cmp(a: uint, b: uint) -> Ordering {
2455
2455
}
2456
2456
```
2457
2457
2458
- ### Complete!
2458
+ ## Complete!
2459
2459
2460
2460
At this point, you have successfully built the Guessing Game! Congratulations!
2461
2461
@@ -2467,36 +2467,36 @@ rest of your Rust education.
2467
2467
Now that you're an expert at the basics, it's time to learn about some of
2468
2468
Rust's more unique features.
2469
2469
2470
- ## iterators
2470
+ # iterators
2471
2471
2472
- ## Lambdas
2472
+ # Lambdas
2473
2473
2474
- ## Testing
2474
+ # Testing
2475
2475
2476
2476
attributes
2477
2477
2478
2478
stability markers
2479
2479
2480
- ## Crates and Modules
2480
+ # Crates and Modules
2481
2481
2482
2482
visibility
2483
2483
2484
2484
2485
- ## Generics
2485
+ # Generics
2486
2486
2487
- ## Traits
2487
+ # Traits
2488
2488
2489
- ## Operators and built-in Traits
2489
+ # Operators and built-in Traits
2490
2490
2491
- ## Ownership and Lifetimes
2491
+ # Ownership and Lifetimes
2492
2492
2493
2493
Move vs. Copy
2494
2494
2495
2495
Allocation
2496
2496
2497
- ## Tasks
2497
+ # Tasks
2498
2498
2499
- ## Macros
2499
+ # Macros
2500
2500
2501
- ## Unsafe
2501
+ # Unsafe
2502
2502
0 commit comments