@@ -7,7 +7,7 @@ displayed here in line with Rust's open development policy. Please open any
77issues you find as usual.
88</div >
99
10- ## Welcome!
10+ # Welcome!
1111
1212Hey there! Welcome to the Rust guide. This is the place to be if you'd like to
1313learn how to program in Rust. Rust is a systems programming language with a
@@ -24,7 +24,7 @@ more advanced things.
2424
2525Sound good? Let's go!
2626
27- ## Installing Rust
27+ # Installing Rust
2828
2929The first step to using Rust is to install it! There are a number of ways to
3030install 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
106106subreddit] ( http://www.reddit.com/r/rust ) , and [ Stack
107107Overflow] ( http://stackoverflow.com/questions/tagged/rust ) .
108108
109- ## Hello, world!
109+ # Hello, world!
110110
111111Now that you have Rust installed, let's write your first Rust program. It's
112112traditional 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
266266that it has, and to make it easy to share your code with other people and
267267projects.
268268
269- ## Hello, Cargo!
269+ # Hello, Cargo!
270270
271271[ Cargo] ( http://crates.io ) is a tool that Rustaceans use to help manage their
272272Rust 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
362362language itself. These are the basics that will serve you well through the rest
363363of your time with Rust.
364364
365- ## Variable bindings
365+ # Variable bindings
366366
367367The first thing we'll learn about are 'variable bindings.' They look like this:
368368
@@ -532,7 +532,7 @@ must initialize the binding before we use it? And how does it know that we have
532532or have not initialized the binding? For that, we need to learn our next
533533concept: ` if ` .
534534
535- ## If
535+ # If
536536
537537Rust's take on ` if ` is not particularly complex, but it's much more like the
538538` 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
593593language, and semicolons are different than in other 'curly brace and
594594semicolon'-based languages. These two things are related.
595595
596- ### Expressions vs. Statements
596+ ## Expressions vs. Statements
597597
598598Rust is primarily an expression based language. There are only two kinds of
599599statements, and everything else is an expression.
@@ -681,7 +681,7 @@ unit instead.
681681There's one more time in which you won't see a semicolon at the end of a line
682682of Rust code. For that, we'll need our next concept: functions.
683683
684- ## Functions
684+ # Functions
685685
686686You've already seen one function so far, the ` main ` function:
687687
@@ -829,7 +829,7 @@ There are some additional ways to define functions, but they involve features
829829that we haven't learned about yet, so let's just leave it at that for now.
830830
831831
832- ## Comments
832+ # Comments
833833
834834Now that we have some functions, it's a good idea to learn about comments.
835835Comments 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
877877comments. We will talk more about ` rustdoc ` when we get to modules, as
878878generally, you want to export documentation for a full module.
879879
880- ## Compound Data Types
880+ # Compound Data Types
881881
882882Rust, like many programming languages, has a number of different data types
883883that are built-in. You've already done some simple work with integers and
884884strings, but next, let's talk about some more complicated ways of storing data.
885885
886- ### Tuples
886+ ## Tuples
887887
888888The first compound data type we're going to talk about are called ** tuple** s.
889889Tuples are an ordered list of a fixed size. Like this:
@@ -958,7 +958,7 @@ can destructure a pattern returned by a function, as well.
958958Tuples are a very simple data structure, and so are not often what you want.
959959Let's move on to their bigger sibling, structs.
960960
961- ### Structs
961+ ## Structs
962962
963963A struct is another form of a 'record type,' just like a tuple. There's a
964964difference: structs give each element that they contain a name, called a
@@ -1008,7 +1008,7 @@ fn main() {
10081008
10091009This will print ` The point is at (5, 0) ` .
10101010
1011- ### Tuple Structs and Newtypes
1011+ ## Tuple Structs and Newtypes
10121012
10131013Rust has another data type that's like a hybrid between a tuple and a struct,
10141014called a ** tuple struct** . Tuple structs do have a name, but their fields
@@ -1064,7 +1064,7 @@ println!("length is {} inches", integer_length);
10641064As you can see here, you can extract the inner integer type through a
10651065destructuring ` let ` .
10661066
1067- ### Enums
1067+ ## Enums
10681068
10691069Finally, Rust has a "sum type", an ** enum** . Enums are an incredibly useful
10701070feature 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
11611161talk about how to fix this big ` if ` /` else ` statements we've been writing. We'll
11621162do that with ` match ` .
11631163
1164- ## Match
1164+ # Match
11651165
11661166Often, a simple ` if ` /` else ` isn't enough, because you have more than two
11671167possible options. And ` else ` conditions can get incredibly complicated. So
@@ -1283,12 +1283,12 @@ fn main() {
12831283In this case, it doesn't make a lot of sense, as we are just making a temporary
12841284string where we don't need to, but sometimes, it's a nice pattern.
12851285
1286- ## Looping
1286+ # Looping
12871287
12881288Looping is the last basic construct that we haven't learned yet in Rust. Rust has
12891289two main looping constructs: ` for ` and ` while ` .
12901290
1291- ### ` for `
1291+ ## ` for `
12921292
12931293The ` for ` loop is used to loop a particular number of times. Rust's ` for ` loops
12941294work 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.
13371337
13381338We'll talk more about ` for ` when we cover ** vector** s, later in the Guide.
13391339
1340- ### ` while `
1340+ ## ` while `
13411341
13421342The other kind of looping construct in Rust is the ` while ` loop. It looks like
13431343this:
@@ -1375,7 +1375,7 @@ general, the more information we can give to the compiler, the better it
13751375can do with safety and code generation. So you should always prefer
13761376` loop ` when you plan to loop infinitely.
13771377
1378- ### Ending iteration early
1378+ ## Ending iteration early
13791379
13801380Let's take a look at that ` while ` loop we had earlier:
13811381
@@ -1426,7 +1426,7 @@ building our guessing game, but we need to know how to do one last thing first:
14261426get input from the keyboard. You can't have a guessing game without the ability
14271427to guess!
14281428
1429- ## Standard Input
1429+ # Standard Input
14301430
14311431Getting input from the keyboard is pretty easy, but uses some things
14321432we haven't seen before. Here's a simple program that reads some input,
@@ -1586,7 +1586,7 @@ here.
15861586That's all you need to get basic input from the standard input! It's not too
15871587complicated, but there are a number of small parts.
15881588
1589- ## Guessing Game
1589+ # Guessing Game
15901590
15911591Okay! We've got the basics of Rust down. Let's write a bigger program.
15921592
@@ -1597,7 +1597,7 @@ Upon entering our guess, it will tell us if we're too low or too high. Once we
15971597guess correctly, it will congratulate us, and print the number of guesses we've
15981598taken to the screen. Sound good?
15991599
1600- ### Set up
1600+ ## Set up
16011601
16021602Let's set up a new project. Go to your projects directory, and make a new
16031603directory 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
16451645our code in this file. We'll talk about multiple-file projects later on in the
16461646guide.
16471647
1648- ### Processing a Guess
1648+ ## Processing a Guess
16491649
16501650Let's get to it! The first thing we need to do for our guessing game is
16511651allow 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.
16741674Because we talked about this in the section on standard I/O, I won't go into
16751675more details here. If you need a refresher, go re-read that section.
16761676
1677- ### Generating a secret number
1677+ ## Generating a secret number
16781678
16791679Next, we need to generate a secret number. To do that, we need to use Rust's
16801680random number generation, which we haven't talked about yet. Rust includes a
@@ -1845,7 +1845,7 @@ You guessed: 3
18451845
18461846Great! Next up: let's compare our guess to the secret guess.
18471847
1848- ### Comparing guesses
1848+ ## Comparing guesses
18491849
18501850If you remember, earlier in the tutorial, we made a ` cmp ` function that compared
18511851two 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.
21942194Now we've got most of the game working, but we can only make one guess. Let's
21952195change that by adding loops!
21962196
2197- ### Looping
2197+ ## Looping
21982198
21992199As we already discussed, the ` loop ` key word gives us an infinite loop. So
22002200let's add that in:
@@ -2455,7 +2455,7 @@ fn cmp(a: uint, b: uint) -> Ordering {
24552455}
24562456```
24572457
2458- ### Complete!
2458+ ## Complete!
24592459
24602460At this point, you have successfully built the Guessing Game! Congratulations!
24612461
@@ -2467,36 +2467,36 @@ rest of your Rust education.
24672467Now that you're an expert at the basics, it's time to learn about some of
24682468Rust's more unique features.
24692469
2470- ## iterators
2470+ # iterators
24712471
2472- ## Lambdas
2472+ # Lambdas
24732473
2474- ## Testing
2474+ # Testing
24752475
24762476attributes
24772477
24782478stability markers
24792479
2480- ## Crates and Modules
2480+ # Crates and Modules
24812481
24822482visibility
24832483
24842484
2485- ## Generics
2485+ # Generics
24862486
2487- ## Traits
2487+ # Traits
24882488
2489- ## Operators and built-in Traits
2489+ # Operators and built-in Traits
24902490
2491- ## Ownership and Lifetimes
2491+ # Ownership and Lifetimes
24922492
24932493Move vs. Copy
24942494
24952495Allocation
24962496
2497- ## Tasks
2497+ # Tasks
24982498
2499- ## Macros
2499+ # Macros
25002500
2501- ## Unsafe
2501+ # Unsafe
25022502
0 commit comments