@@ -9,7 +9,7 @@ thing to do.
9
9
10
10
The first thing that we need to do is make a file to put our code in. I like to
11
11
make a ` projects ` directory in my home directory, and keep all my projects
12
- there. Rust does not care where our code lives.
12
+ there. Rust doesn't care where our code lives.
13
13
14
14
This actually leads to one other concern we should address: this guide will
15
15
assume that we have basic familiarity with the command line. Rust itself makes
@@ -71,10 +71,10 @@ were arguments, they would go inside the parentheses (`(` and `)`), and because
71
71
we aren’t returning anything from this function, we can omit the return type
72
72
entirely. We’ll get to it later.
73
73
74
- We ’ll also note that the function is wrapped in curly braces (` { ` and ` } ` ). Rust
75
- requires these around all function bodies. It is also considered good style to
76
- put the opening curly brace on the same line as the function declaration, with
77
- one space in between.
74
+ You ’ll also note that the function is wrapped in curly braces (` { ` and ` } ` ).
75
+ Rust requires these around all function bodies. It is also considered good style
76
+ to put the opening curly brace on the same line as the function declaration,
77
+ with one space in between.
78
78
79
79
Next up is this line:
80
80
@@ -84,29 +84,29 @@ Next up is this line:
84
84
85
85
This line does all of the work in our little program. There are a number of
86
86
details that are important here. The first is that it’s indented with four
87
- spaces, not tabs. Please configure our editor of choice to insert four spaces
88
- with the tab key. We provide some [ sample configurations for various
89
- editors] [ configs ] .
87
+ spaces, not tabs. Please configure your editor of choice to insert four spaces
88
+ with the tab key. We provide some
89
+ [ sample configurations for various editors] [ configs ] .
90
90
91
91
[ configs ] : https://github.com/rust-lang/rust/tree/master/src/etc/CONFIGS.md
92
92
93
93
The second point is the ` println!() ` part. This is calling a Rust
94
94
[ macro] [ macro ] , which is how metaprogramming is done in Rust. If it were a
95
95
function instead, it would look like this: ` println() ` . For our purposes, we
96
- don’t need to worry about this difference. Just know that sometimes, we’ll see a ` ! ` ,
97
- and that means that we’re calling a macro instead of a normal function. Rust
98
- implements ` println! ` as a macro rather than a function for good reasons, but
99
- that's an advanced topic. One last thing to mention: Rust’s macros are
100
- significantly different from C macros, if we ’ve used those. Don’t be scared of
101
- using macros. We’ll get to the details eventually, we ’ll just have to take it on
102
- trust for now.
96
+ don’t need to worry about this difference. Just know that sometimes, we’ll see a
97
+ ` ! ` , and that means that we’re calling a macro instead of a normal function.
98
+ Rust implements ` println! ` as a macro rather than a function for good reasons,
99
+ but that's an advanced topic. One last thing to mention: Rust’s macros are
100
+ significantly different from C macros, if you ’ve used those. Don’t be scared of
101
+ using macros. We’ll get to the details eventually, you ’ll just have to take it
102
+ on trust for now.
103
103
104
104
[ macro ] : macros.html
105
105
106
106
Next, ` "Hello, world!" ` is a ‘string’. Strings are a surprisingly complicated
107
107
topic in a systems programming language, and this is a ‘statically allocated’
108
- string. If we want to read further about allocation, check out [ the stack and
109
- the heap] [ allocation ] , but we don’t need to right now if we don’t want to. We
108
+ string. If you want to read further about allocation, check out [ the stack and
109
+ the heap] [ allocation ] , but you don’t need to right now if you don’t want to. We
110
110
pass this string as an argument to ` println! ` , which prints the string to the
111
111
screen. Easy enough!
112
112
@@ -127,8 +127,8 @@ compiler, `rustc`, by passing it the name of our source file:
127
127
$ rustc main.rs
128
128
```
129
129
130
- This is similar to ` gcc ` or ` clang ` , if we come from a C or C++ background. Rust
131
- will output a binary executable. We can see it with ` ls ` :
130
+ This is similar to ` gcc ` or ` clang ` , if you come from a C or C++ background.
131
+ Rust will output a binary executable. We can see it with ` ls ` :
132
132
133
133
``` bash
134
134
$ ls
@@ -151,18 +151,19 @@ $ ./main # or main.exe on Windows
151
151
152
152
This prints out our ` Hello, world! ` text to our terminal.
153
153
154
- If we come from a dynamic language like Ruby, Python, or JavaScript, we may not
155
- be used to these two steps being separate. Rust is an ‘ahead-of-time compiled
156
- language’, which means that we can compile a program, give it to someone else,
157
- and they don't need to have Rust installed. If we give someone a ` .rb ` or ` .py `
158
- or ` .js ` file, they need to have a Ruby/Python/JavaScript implementation
159
- installed, but we just need one command to both compile and run our program.
160
- Everything is a tradeoff in language design, and Rust has made its choice.
154
+ If you come from a dynamic language like Ruby, Python, or JavaScript, you may
155
+ not be used to these two steps being separate. Rust is an ‘ahead-of-time
156
+ compiled language’, which means that we can compile a program, give it to
157
+ someone else, and they don't need to have Rust installed. If we give someone a
158
+ ` .rb ` or ` .py ` or ` .js ` file, they need to have a Ruby/Python/JavaScript
159
+ implementation installed, but we just need one command to both compile and run
160
+ our program. Everything is a tradeoff in language design, and Rust has made its
161
+ choice.
161
162
162
- Congratulations! We have officially written a Rust program. That makes us Rust
163
- programmers ! Welcome. 🎊🎉👍
163
+ Congratulations! You have officially written a Rust program. That makes you a
164
+ Rust programmer ! Welcome. 🎊🎉👍
164
165
165
- Next, I'd like to introduce us to another tool, Cargo, which is used to write
166
+ Next, I'd like to introduce you to another tool, Cargo, which is used to write
166
167
real-world Rust programs. Just using ` rustc ` is nice for simple things, but as
167
168
our project grows, we'll want something to help us manage all of the options
168
169
that it has, and to make it easy to share our code with other people and
0 commit comments