Skip to content

Commit 8794107

Browse files
committed
auto merge of #17754 : O-I/rust/update-guide, r=steveklabnik
Hi, These are a few small edits to the Guide that I made while reading online. Really well done and approachable. I have a few questions below, but I don't know if this is the proper place to ask them, so feel free to ignore the below. 1. Trailing commas seem to be a convention in Rust and are used quite a bit throughout the Guide, but are never explicitly mentioned. Maybe adding a short mention about them when they first appear in the Structs section might be helpful to those who are unfamiliar with or don't use them in other languages. 2. In the Iterators section, there is a block of code like this: ```rust let mut range = range(0i, 10i); loop { match range.next() { Some(x) => { println!("{}", x); } // no comma needed? None => { break } } } ``` My inclination would be to put a comma where the comment is to separate the two arms to get this to compile, but it runs fine either way. Is there a convention on commas for scenarios like this where each arm is enclosed in `{}`? All the best, O-I
2 parents 908c9e6 + 9040948 commit 8794107

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

src/doc/guide.md

+16-17
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ struct Point {
961961
}
962962

963963
fn main() {
964-
let origin = Point { x: 0i, y: 0i };
964+
let origin = Point { x: 0i, y: 0i };
965965

966966
println!("The origin is at ({}, {})", origin.x, origin.y);
967967
}
@@ -988,7 +988,7 @@ struct Point {
988988
}
989989
990990
fn main() {
991-
let mut point = Point { x: 0i, y: 0i };
991+
let mut point = Point { x: 0i, y: 0i };
992992
993993
point.x = 5;
994994
@@ -1140,13 +1140,13 @@ You can have any number of values in an enum:
11401140
```{rust}
11411141
enum OptionalColor {
11421142
Color(int, int, int),
1143-
Missing
1143+
Missing,
11441144
}
11451145
```
11461146

11471147
Enums with values are quite useful, but as I mentioned, they're even more
11481148
useful when they're generic across types. But before we get to generics, let's
1149-
talk about how to fix this big `if`/`else` statements we've been writing. We'll
1149+
talk about how to fix these big `if`/`else` statements we've been writing. We'll
11501150
do that with `match`.
11511151

11521152
# Match
@@ -1561,7 +1561,7 @@ println!("The second name is: {}", names[1]);
15611561

15621562
These subscripts start at zero, like in most programming languages, so the
15631563
first name is `names[0]` and the second name is `names[1]`. The above example
1564-
prints `The second name is Brian`.
1564+
prints `The second name is: Brian`.
15651565

15661566
There's a whole lot more to vectors, but that's enough to get started. We have
15671567
now learned all of the most basic Rust concepts. We're ready to start building
@@ -2084,7 +2084,7 @@ fn main() {
20842084
match cmp(input, secret_number) {
20852085
Less => println!("Too small!"),
20862086
Greater => println!("Too big!"),
2087-
Equal => { println!("You win!"); },
2087+
Equal => println!("You win!"),
20882088
}
20892089
}
20902090
@@ -2176,14 +2176,12 @@ fn main() {
21762176
.expect("Failed to read line");
21772177
let input_num: Option<uint> = from_str(input.as_slice());
21782178
2179-
2180-
21812179
println!("You guessed: {}", input_num);
21822180
21832181
match cmp(input_num, secret_number) {
21842182
Less => println!("Too small!"),
21852183
Greater => println!("Too big!"),
2186-
Equal => { println!("You win!"); },
2184+
Equal => println!("You win!"),
21872185
}
21882186
}
21892187
@@ -2241,7 +2239,7 @@ fn main() {
22412239
match cmp(num, secret_number) {
22422240
Less => println!("Too small!"),
22432241
Greater => println!("Too big!"),
2244-
Equal => { println!("You win!"); },
2242+
Equal => println!("You win!"),
22452243
}
22462244
}
22472245
@@ -2307,7 +2305,7 @@ fn main() {
23072305
match cmp(num, secret_number) {
23082306
Less => println!("Too small!"),
23092307
Greater => println!("Too big!"),
2310-
Equal => { println!("You win!"); },
2308+
Equal => println!("You win!"),
23112309
}
23122310
}
23132311
@@ -2382,7 +2380,7 @@ fn main() {
23822380
match cmp(num, secret_number) {
23832381
Less => println!("Too small!"),
23842382
Greater => println!("Too big!"),
2385-
Equal => { println!("You win!"); },
2383+
Equal => println!("You win!"),
23862384
}
23872385
}
23882386
}
@@ -2619,7 +2617,7 @@ Rust's more unique features.
26192617

26202618
Rust features a strong module system, but it works a bit differently than in
26212619
other programming languages. Rust's module system has two main components:
2622-
**crate**s, and **module**s.
2620+
**crate**s and **module**s.
26232621

26242622
A crate is Rust's unit of independent compilation. Rust always compiles one
26252623
crate at a time, producing either a library or an executable. However, executables
@@ -2640,6 +2638,7 @@ Enough talk, let's build something! Let's make a new project called `modules`.
26402638
```{bash,ignore}
26412639
$ cd ~/projects
26422640
$ cargo new modules --bin
2641+
$ cd modules
26432642
```
26442643

26452644
Let's double check our work by compiling:
@@ -3622,7 +3621,7 @@ let x = box 5i;
36223621
```
36233622

36243623
This allocates an integer `5` on the heap, and creates a binding `x` that
3625-
refers to it.. The great thing about boxed pointers is that we don't have to
3624+
refers to it. The great thing about boxed pointers is that we don't have to
36263625
manually free this allocation! If we write
36273626

36283627
```{rust}
@@ -3994,7 +3993,7 @@ Let's make a closure:
39943993
```{rust}
39953994
let add_one = |x| { 1i + x };
39963995
3997-
println!("The 5 plus 1 is {}.", add_one(5i));
3996+
println!("The sum of 5 plus 1 is {}.", add_one(5i));
39983997
```
39993998

40003999
We create a closure using the `|...| { ... }` syntax, and then we create a
@@ -4089,7 +4088,7 @@ fn main() {
40894088
}
40904089
```
40914090

4092-
Let's break example down, starting with `main`:
4091+
Let's break the example down, starting with `main`:
40934092

40944093
```{rust}
40954094
let square = |x: int| { x * x };
@@ -4210,7 +4209,7 @@ loop {
42104209
match range.next() {
42114210
Some(x) => {
42124211
println!("{}", x);
4213-
}
4212+
},
42144213
None => { break }
42154214
}
42164215
}

0 commit comments

Comments
 (0)