Skip to content

Commit a2a1be1

Browse files
authored
Merge pull request #1189 from Xmasreturns/chapter_1_edits
Copy edits to chapter 1
2 parents af433fa + 765b4c4 commit a2a1be1

File tree

7 files changed

+40
-40
lines changed

7 files changed

+40
-40
lines changed

src/hello.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
This is the source code of the traditional Hello World program.
44

55
```rust,editable
6-
// This is a comment, and will be ignored by the compiler
6+
// This is a comment, and is ignored by the compiler
77
// You can test this code by clicking the "Run" button over there ->
8-
// or if prefer to use your keyboard, you can use the "Ctrl + Enter" shortcut
8+
// or if you prefer to use your keyboard, you can use the "Ctrl + Enter" shortcut
99
1010
// This code is editable, feel free to hack it!
1111
// You can always return to the original code by clicking the "Reset" button ->
1212
1313
// This is the main function
1414
fn main() {
15-
// The statements here will be executed when the compiled binary is called
15+
// Statements here are executed when the compiled binary is called
1616
1717
// Print text to the console
1818
println!("Hello World!");

src/hello/comment.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
11
# Comments
22

3-
Any program requires comments and indeed Rust supports
3+
Any program requires comments, and Rust supports
44
a few different varieties:
55

66
* *Regular comments* which are ignored by the compiler:
7-
- `// Line comments which go to the end of the line.`
8-
- `/* Block comments which go to the closing delimiter. */`
7+
* `// Line comments which go to the end of the line.`
8+
* `/* Block comments which go to the closing delimiter. */`
99
* *Doc comments* which are parsed into HTML library
10-
[documentation][docs]:
11-
- `/// Generate library docs for the following item.`
12-
- `//! Generate library docs for the enclosing item.`
10+
[documentation][docs]:
11+
* `/// Generate library docs for the following item.`
12+
* `//! Generate library docs for the enclosing item.`
1313

1414
```rust,editable
1515
fn main() {
1616
// This is an example of a line comment
17-
// Notice how there are two slashes at the beginning of the line
18-
// And that nothing written inside these will be read by the compiler
17+
// There are two slashes at the beginning of the line
18+
// And nothing written inside these will be read by the compiler
1919
2020
// println!("Hello, world!");
2121
2222
// Run it. See? Now try deleting the two slashes, and run it again.
2323
2424
/*
25-
* This is another type of comment, the block comment. In general,
26-
* the line comment is the recommended comment style however the
27-
* block comment is extremely useful for temporarily disabling
28-
* a large chunk of code. /* Block comments can be /* nested, */ */
29-
* so it takes only a few keystrokes to comment out all the lines
25+
* This is another type of comment, a block comment. In general,
26+
* line comments are the recommended comment style. But
27+
* block comments are extremely useful for temporarily disabling
28+
* chunks of code. /* Block comments can be /* nested, */ */
29+
* so it takes only a few keystrokes to comment out everything
3030
* in this main() function. /*/*/* Try it yourself! */*/*/
3131
*/
3232
3333
/*
34-
Note, the previous column of `*` was entirely for style. There's
34+
Note: The previous column of `*` was entirely for style. There's
3535
no actual need for it.
3636
*/
3737
38-
// Observe how block comments allow easy expression manipulation
39-
// which line comments do not. Deleting the comment delimiters
40-
// will change the result:
38+
// You can manipulate expressions more easily with block comments
39+
// than with line comments. Try deleting the comment delimiters
40+
// to change the result:
4141
let x = 5 + /* 90 + */ 5;
4242
println!("Is `x` 10 or 100? x = {}", x);
4343
}

src/hello/print.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ some of which include:
99
* `eprint!`: same as `format!` but the text is printed to the standard error (io::stderr).
1010
* `eprintln!`: same as `eprint!`but a newline is appended.
1111

12-
All parse text in the same fashion. A plus is that the formatting correctness will
13-
be checked at compile time.
12+
All parse text in the same fashion. As a plus, Rust checks formatting
13+
correctness at compile time.
1414

1515
```rust,editable,ignore,mdbook-runnable
1616
fn main() {
1717
// In general, the `{}` will be automatically replaced with any
1818
// arguments. These will be stringified.
1919
println!("{} days", 31);
2020
21-
// Without a suffix, 31 becomes an i32. You can change what type 31 is,
22-
// with a suffix.
21+
// Without a suffix, 31 becomes an i32. You can change what type 31 is
22+
// by providing a suffix.
2323
2424
// There are various optional patterns this works with. Positional
2525
// arguments can be used.
@@ -41,12 +41,12 @@ fn main() {
4141
// You can pad numbers with extra zeroes. This will output "000001".
4242
println!("{number:>0width$}", number=1, width=6);
4343
44-
// It will even check to make sure the correct number of arguments are
44+
// Rust even checks to make sure the correct number of arguments are
4545
// used.
4646
println!("My name is {0}, {1} {0}", "Bond");
4747
// FIXME ^ Add the missing argument: "James"
4848
49-
// Create a structure which contains an `i32`. Name it `Structure`.
49+
// Create a structure named `Structure` which contains an `i32`.
5050
#[allow(dead_code)]
5151
struct Structure(i32);
5252
@@ -64,7 +64,7 @@ of text. The base form of two important ones are listed below:
6464
* `fmt::Display`: Uses the `{}` marker. Format text in a more elegant, user
6565
friendly fashion.
6666

67-
Here, `fmt::Display` was used because the std library provides implementations
67+
Here, we used `fmt::Display `because the std library provides implementations
6868
for these types. To print text for custom types, more steps are required.
6969

7070
Implementing the `fmt::Display` trait automagically implements the
@@ -76,7 +76,7 @@ Implementing the `fmt::Display` trait automagically implements the
7676
error.
7777
* Add a `println!` macro that prints: `Pi is roughly 3.142` by controlling
7878
the number of decimal places shown. For the purposes of this exercise,
79-
use `let pi = 3.141592` as an estimate for Pi. (Hint: you may need to
79+
use `let pi = 3.141592` as an estimate for pi. (Hint: you may need to
8080
check the [`std::fmt`][fmt] documentation for setting the number of
8181
decimals to display)
8282

src/hello/print/fmt.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ struct City {
2626
}
2727
2828
impl Display for City {
29-
// `f` is a buffer, this method must write the formatted string into it
29+
// `f` is a buffer, and this method must write the formatted string into it
3030
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
3131
let lat_c = if self.lat >= 0.0 { 'N' } else { 'S' };
3232
let lon_c = if self.lon >= 0.0 { 'E' } else { 'W' };
@@ -59,7 +59,7 @@ fn main() {
5959
Color { red: 0, green: 0, blue: 0 },
6060
].iter() {
6161
// Switch this to use {} once you've added an implementation
62-
// for fmt::Display
62+
// for fmt::Display.
6363
println!("{:?}", *color);
6464
}
6565
}

src/hello/print/print_debug.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ not true for `fmt::Display` which must be manually implemented.
1111

1212
```rust
1313
// This structure cannot be printed either with `fmt::Display` or
14-
// with `fmt::Debug`
14+
// with `fmt::Debug`.
1515
struct UnPrintable(i32);
1616

1717
// The `derive` attribute automatically creates the implementation

src/hello/print/print_display.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ looks like this:
99
// Import (via `use`) the `fmt` module to make it available.
1010
use std::fmt;
1111

12-
// Define a structure which `fmt::Display` will be implemented for. This is simply
13-
// a tuple struct containing an `i32` bound to the name `Structure`.
12+
// Define a structure for which `fmt::Display` will be implemented. This is
13+
// a tuple struct named `Structure` that contains an `i32`.
1414
struct Structure(i32);
1515

16-
// In order to use the `{}` marker, the trait `fmt::Display` must be implemented
16+
// To use the `{}` marker, the trait `fmt::Display` must be implemented
1717
// manually for the type.
1818
impl fmt::Display for Structure {
1919
// This trait requires `fmt` with this exact signature.
@@ -30,7 +30,7 @@ impl fmt::Display for Structure {
3030
`fmt::Display` may be cleaner than `fmt::Debug` but this presents
3131
a problem for the `std` library. How should ambiguous types be displayed?
3232
For example, if the `std` library implemented a single style for all
33-
`Vec<T>`, what style should it be? Either of these two?
33+
`Vec<T>`, what style should it be? Would it be either of these two?
3434

3535
* `Vec<path>`: `/:/etc:/home/username:/bin` (split on `:`)
3636
* `Vec<number>`: `1,2,3` (split on `,`)
@@ -66,7 +66,7 @@ struct Point2D {
6666
y: f64,
6767
}
6868
69-
// Similarly, implement for Point2D
69+
// Similarly, implement `Display` for `Point2D`
7070
impl fmt::Display for Point2D {
7171
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7272
// Customize so only `x` and `y` are denoted.
@@ -94,7 +94,7 @@ fn main() {
9494
println!("Display: {}", point);
9595
println!("Debug: {:?}", point);
9696
97-
// Error. Both `Debug` and `Display` were implemented but `{:b}`
97+
// Error. Both `Debug` and `Display` were implemented, but `{:b}`
9898
// requires `fmt::Binary` to be implemented. This will not work.
9999
// println!("What does Point2D look like in binary: {:b}?", point);
100100
}
@@ -107,7 +107,7 @@ each requires its own implementation. This is detailed further in
107107

108108
### Activity
109109

110-
After checking the output of the above example, use the `Point2D` struct as
110+
After checking the output of the above example, use the `Point2D` struct as a
111111
guide to add a Complex struct to the example. When printed in the same
112112
way, the output should be:
113113

src/hello/print/print_display/testcase_list.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct List(Vec<i32>);
3232
3333
impl fmt::Display for List {
3434
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
35-
// Extract the value using tuple indexing
35+
// Extract the value using tuple indexing,
3636
// and create a reference to `vec`.
3737
let vec = &self.0;
3838
@@ -47,7 +47,7 @@ impl fmt::Display for List {
4747
write!(f, "{}", v)?;
4848
}
4949
50-
// Close the opened bracket and return a fmt::Result value
50+
// Close the opened bracket and return a fmt::Result value.
5151
write!(f, "]")
5252
}
5353
}

0 commit comments

Comments
 (0)