@@ -150,7 +150,7 @@ in your file name, use an underscore. `hello_world.rs` versus `goodbye.rs`.
150
150
151
151
Now that you've got your file open, type this in:
152
152
153
- ```
153
+ ``` {rust}
154
154
fn main() {
155
155
println!("Hello, world!");
156
156
}
@@ -166,7 +166,7 @@ Hello, world!
166
166
167
167
Success! Let's go over what just happened in detail.
168
168
169
- ```
169
+ ``` {rust}
170
170
fn main() {
171
171
172
172
}
@@ -186,7 +186,7 @@ declaration, with one space in between.
186
186
187
187
Next up is this line:
188
188
189
- ```
189
+ ``` {rust}
190
190
println!("Hello, world!");
191
191
```
192
192
@@ -562,7 +562,7 @@ the block is executed. If it's `false`, then it is not.
562
562
563
563
If you want something to happen in the ` false ` case, use an ` else ` :
564
564
565
- ```
565
+ ``` {rust}
566
566
let x = 5i;
567
567
568
568
if x == 5i {
@@ -574,7 +574,8 @@ if x == 5i {
574
574
575
575
This is all pretty standard. However, you can also do this:
576
576
577
- ```
577
+
578
+ ``` {rust}
578
579
let x = 5i;
579
580
580
581
let y = if x == 5i {
@@ -586,7 +587,7 @@ let y = if x == 5i {
586
587
587
588
Which we can (and probably should) write like this:
588
589
589
- ```
590
+ ``` {rust}
590
591
let x = 5i;
591
592
592
593
let y = if x == 5i { 10i } else { 15i };
@@ -643,7 +644,7 @@ every line of Rust code you see.
643
644
What is this exception that makes us say 'almost?' You saw it already, in this
644
645
code:
645
646
646
- ```
647
+ ``` {rust}
647
648
let x = 5i;
648
649
649
650
let y: int = if x == 5i { 10i } else { 15i };
@@ -989,7 +990,7 @@ notation: `origin.x`.
989
990
The values in structs are immutable, like other bindings in Rust. However, you
990
991
can use ` mut ` to make them mutable:
991
992
992
- ``` rust
993
+ ``` { rust}
993
994
struct Point {
994
995
x: int,
995
996
y: int,
@@ -1013,7 +1014,7 @@ called a **tuple struct**. Tuple structs do have a name, but their fields
1013
1014
don't:
1014
1015
1015
1016
1016
- ```
1017
+ ``` {rust}
1017
1018
struct Color(int, int, int);
1018
1019
struct Point(int, int, int);
1019
1020
```
@@ -1028,7 +1029,7 @@ let origin = Point(0, 0, 0);
1028
1029
It is almost always better to use a struct than a tuple struct. We would write
1029
1030
` Color ` and ` Point ` like this instead:
1030
1031
1031
- ``` rust
1032
+ ``` { rust}
1032
1033
struct Color {
1033
1034
red: int,
1034
1035
blue: int,
@@ -1049,7 +1050,7 @@ There _is_ one case when a tuple struct is very useful, though, and that's a
1049
1050
tuple struct with only one element. We call this a 'newtype,' because it lets
1050
1051
you create a new type that's a synonym for another one:
1051
1052
1052
- ```
1053
+ ``` {rust}
1053
1054
struct Inches(int);
1054
1055
1055
1056
let length = Inches(10);
@@ -1166,7 +1167,7 @@ what's the solution?
1166
1167
Rust has a keyword, ` match ` , that allows you to replace complicated ` if ` /` else `
1167
1168
groupings with something more powerful. Check it out:
1168
1169
1169
- ``` rust
1170
+ ``` { rust}
1170
1171
let x = 5i;
1171
1172
1172
1173
match x {
@@ -1407,7 +1408,7 @@ We now loop forever with `loop`, and use `break` to break out early.
1407
1408
` continue ` is similar, but instead of ending the loop, goes to the next
1408
1409
iteration: This will only print the odd numbers:
1409
1410
1410
- ```
1411
+ ``` {rust}
1411
1412
for x in range(0i, 10i) {
1412
1413
if x % 2 == 0 { continue; }
1413
1414
@@ -4122,7 +4123,7 @@ the ability to use this **method call syntax** via the `impl` keyword.
4122
4123
4123
4124
Here's how it works:
4124
4125
4125
- ```
4126
+ ``` {rust}
4126
4127
struct Circle {
4127
4128
x: f64,
4128
4129
y: f64,
@@ -4161,7 +4162,7 @@ multiplications later, and we have our area.
4161
4162
You can also define methods that do not take a ` self ` parameter. Here's a
4162
4163
pattern that's very common in Rust code:
4163
4164
4164
- ```
4165
+ ``` {rust}
4165
4166
struct Circle {
4166
4167
x: f64,
4167
4168
y: f64,
0 commit comments