Skip to content

Commit 8bede1b

Browse files
authored
Merge pull request #1888 from ShapelessCat/minor-improvements
Minor improvements
2 parents 4dafcae + 0e22153 commit 8bede1b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+242
-205
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@ book
22

33
po/messages.pot
44

5+
.vscode/
6+
57
# Auto-generated files from macOS
68
.DS_Store

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ abide by the [Rust code of conduct], which you can find at that link or in the
1010

1111
## License
1212

13-
RBE is dual licenced under the MIT and Apache 2.0 licenses, and so are all
13+
RBE is dual licensed under the MIT and Apache 2.0 licenses, and so are all
1414
contributions. Please see the [`LICENSE-MIT`] and [`LICENSE-APACHE`] files in
1515
this directory for more details.
1616

@@ -55,7 +55,7 @@ $ mdbook build
5555

5656
**The following warnings can be ignored safely.**
5757

58-
```
58+
```text
5959
[WARN] (mdbook::preprocess::cmd): The command wasn't found, is the "gettext" preprocessor installed?
6060
[WARN] (mdbook::preprocess::cmd): Command: mdbook-gettext
6161
```

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ read all content offline, however!
2626

2727
**The following warnings can be ignored safely.**
2828

29-
```
29+
```text
3030
[WARN] (mdbook::preprocess::cmd): The command wasn't found, is the "gettext" preprocessor installed?
3131
[WARN] (mdbook::preprocess::cmd): Command: mdbook-gettext
3232
```

TRANSLATING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ MDBOOK_OUTPUT='{"xgettext": {"pot-file": "messages.pot"}}' \
3737
msginit -i po/messages.pot -l xx -o po/xx.po
3838
```
3939

40-
#### Updating the exising translation resource
40+
#### Updating the existing translation resource
4141

4242
```bash
4343
msgmerge --update po/xx.po po/messages.pot

src/attribute.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ can be used to/for:
1717
Attributes look like `#[outer_attribute]` or `#![inner_attribute]`,
1818
with the difference between them being where they apply.
1919

20-
- `#[outer_attribute]` applies to the [item][item] immediately
20+
* `#[outer_attribute]` applies to the [item][item] immediately
2121
following it. Some examples of items are: a function, a module
2222
declaration, a constant, a structure, an enum. Here is an example
2323
where attribute `#[derive(Debug)]` applies to the struct
2424
`Rectangle`:
25+
2526
```rust
2627
#[derive(Debug)]
2728
struct Rectangle {
@@ -30,11 +31,12 @@ with the difference between them being where they apply.
3031
}
3132
```
3233

33-
- `#![inner_attribute]` applies to the enclosing [item][item] (typically a
34+
* `#![inner_attribute]` applies to the enclosing [item][item] (typically a
3435
module or a crate). In other words, this attribute is interpreted as
3536
applying to the entire scope in which it's placed. Here is an example
3637
where `#![allow(unused_variables)]` applies to the whole crate (if
3738
placed in `main.rs`):
39+
3840
```rust
3941
#![allow(unused_variables)]
4042

src/cargo/deps.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,5 @@ rebuilds what it has not already built, similar to `make`).
9191

9292
Voila! That's all there is to it!
9393

94-
9594
[manifest]: https://doc.rust-lang.org/cargo/reference/manifest.html
9695
[dependencies]: https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html

src/cargo/test.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
As we know testing is integral to any piece of software! Rust has first-class
44
support for unit and integration testing ([see this
5-
chapter](https://doc.rust-lang.org/book/ch11-00-testing.html) in
6-
TRPL).
5+
chapter](https://doc.rust-lang.org/book/ch11-00-testing.html) in TRPL).
76

87
From the testing chapters linked above, we see how to write unit tests and
98
integration tests. Organizationally, we can place unit tests in the modules they
@@ -20,13 +19,13 @@ foo
2019
└── my_other_test.rs
2120
```
2221

23-
Each file in `tests` is a separate
22+
Each file in `tests` is a separate
2423
[integration test](https://doc.rust-lang.org/book/ch11-03-test-organization.html#integration-tests),
2524
i.e. a test that is meant to test your library as if it were being called from a dependent
2625
crate.
2726

28-
The [Testing][testing] chapter elaborates on the three different testing styles:
29-
[Unit][unit_testing], [Doc][doc_testing], and [Integration][integration_testing].
27+
The [Testing][testing] chapter elaborates on the three different testing styles:
28+
[Unit][unit_testing], [Doc][doc_testing], and [Integration][integration_testing].
3029

3130
`cargo` naturally provides an easy way to run all of your tests!
3231

@@ -71,7 +70,7 @@ test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 2 filtered out
7170
```
7271

7372
One word of caution: Cargo may run multiple tests concurrently, so make sure
74-
that they don't race with each other.
73+
that they don't race with each other.
7574

7675
One example of this concurrency causing issues is if two tests output to a
7776
file, such as below:
@@ -120,6 +119,7 @@ mod tests {
120119
```
121120

122121
Although the intent is to get the following:
122+
123123
```shell
124124
$ cat ferris.txt
125125
Ferris
@@ -133,7 +133,9 @@ Corro
133133
Corro
134134
Corro
135135
```
136+
136137
What actually gets put into `ferris.txt` is this:
138+
137139
```shell
138140
$ cargo test test_file && cat ferris.txt
139141
Corro

src/compatibility.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Compatibility
22

3-
The Rust language is fastly evolving, and because of this certain compatibility
3+
The Rust language is evolving rapidly, and because of this certain compatibility
44
issues can arise, despite efforts to ensure forwards-compatibility wherever
55
possible.
66

src/conversion/from_into.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ fn main() {
7373

7474
`From` and `Into` are designed to be complementary.
7575
We do not need to provide an implementation for both traits.
76-
If you have implemented the `From` trait for your type, `Into` will call it
77-
when necessary. Note, however, that the converse is not true: implementing `Into` for your type will not automatically provide it with an implementation of `From`.
76+
If you have implemented the `From` trait for your type, `Into` will call it
77+
when necessary. Note, however, that the converse is not true: implementing `Into` for your type will not automatically provide it with an implementation of `From`.
7878

7979
```rust,editable
8080
use std::convert::From;

src/conversion/string.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
To convert any type to a `String` is as simple as implementing the [`ToString`]
66
trait for the type. Rather than doing so directly, you should implement the
7-
[`fmt::Display`][Display] trait which automagically provides [`ToString`] and
7+
[`fmt::Display`][Display] trait which automatically provides [`ToString`] and
88
also allows printing the type as discussed in the section on [`print!`][print].
99

1010
```rust,editable

src/crates/lib.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ crate file, but this default name can be overridden by passing
3131
the `--crate-name` option to `rustc` or by using the [`crate_name`
3232
attribute][crate-name].
3333

34-
[crate-name]: ../attribute/crate.md
34+
[crate-name]: ../attribute/crate.md

src/crates/using_lib.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Using a Library
22

3-
To link a crate to this new library you may use `rustc`'s `--extern` flag. All
3+
To link a crate to this new library you may use `rustc`'s `--extern` flag. All
44
of its items will then be imported under a module named the same as the library.
55
This module generally behaves the same way as any other module.
66

src/custom_types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ Rust custom data types are formed mainly through the two keywords:
55
* `struct`: define a structure
66
* `enum`: define an enumeration
77

8-
Constants can also be created via the `const` and `static` keywords.
8+
Constants can also be created via the `const` and `static` keywords.

src/custom_types/enum/enum_use.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn main() {
4444

4545
### See also:
4646

47-
[`match`][match] and [`use`][use]
47+
[`match`][match] and [`use`][use]
4848

4949
[use]: ../../mod/use.md
5050
[match]: ../../flow_control/match.md

src/error/abort_unwind.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# `abort` and `unwind`
22

3-
The previous section illustrates the error handling mechanism `panic`. Different code paths can be conditionally compiled based on the panic setting. The current values available are `unwind` and `abort`.
4-
3+
The previous section illustrates the error handling mechanism `panic`. Different code paths can be conditionally compiled based on the panic setting. The current values available are `unwind` and `abort`.
54

65
Building on the prior lemonade example, we explicitly use the panic strategy to exercise different lines of code.
76

@@ -57,4 +56,3 @@ The panic strategy can be set from the command line by using `abort` or `unwind`
5756
```console
5857
rustc lemonade.rs -C panic=abort
5958
```
60-

src/error/multiple_error_types/define_error_type.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ Rust allows us to define our own error types. In general, a "good" error type:
88
* Represents different errors with the same type
99
* Presents nice error messages to the user
1010
* Is easy to compare with other types
11-
- Good: `Err(EmptyVec)`
12-
- Bad: `Err("Please use a vector with at least one element".to_owned())`
11+
* Good: `Err(EmptyVec)`
12+
* Bad: `Err("Please use a vector with at least one element".to_owned())`
1313
* Can hold information about the error
14-
- Good: `Err(BadChar(c, position))`
15-
- Bad: `Err("+ cannot be used here".to_owned())`
14+
* Good: `Err(BadChar(c, position))`
15+
* Bad: `Err("+ cannot be used here".to_owned())`
1616
* Composes well with other errors
1717

1818
```rust,editable

src/error/multiple_error_types/wrap_error.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ for you.
9292

9393
[`From::from`][from] and [`Enums`][enums]
9494

95-
9695
[`Crates for handling errors`][crates-errors]
9796

9897
[from]: https://doc.rust-lang.org/std/convert/trait.From.html

src/error/option_unwrap.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ We told our program to `panic` if we drink a sugary lemonade.
55
But what if we expect _some_ drink but don't receive one?
66
That case would be just as bad, so it needs to be handled!
77

8-
We *could* test this against the null string (`""`) as we do with a lemonade.
8+
We _could_ test this against the null string (`""`) as we do with a lemonade.
99
Since we're using Rust, let's instead have the compiler point out cases
1010
where there's no drink.
1111

src/error/option_unwrap/and_then.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Combinators: `and_then`
22

3-
`map()` was described as a chainable way to simplify `match` statements.
4-
However, using `map()` on a function that returns an `Option<T>` results
5-
in the nested `Option<Option<T>>`. Chaining multiple calls together can
6-
then become confusing. That's where another combinator called `and_then()`,
3+
`map()` was described as a chainable way to simplify `match` statements.
4+
However, using `map()` on a function that returns an `Option<T>` results
5+
in the nested `Option<Option<T>>`. Chaining multiple calls together can
6+
then become confusing. That's where another combinator called `and_then()`,
77
known in some languages as flatmap, comes in.
88

99
`and_then()` calls its function input with the wrapped value and returns the result. If the `Option` is `None`, then it returns `None` instead.
1010

11-
In the following example, `cookable_v3()` results in an `Option<Food>`.
11+
In the following example, `cookable_v3()` results in an `Option<Food>`.
1212
Using `map()` instead of `and_then()` would have given an
1313
`Option<Option<Food>>`, which is an invalid type for `eat()`.
1414

src/error/option_unwrap/defaults.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# Unpacking options and defaults
22

33
There is more than one way to unpack an `Option` and fall back on a default if it is `None`. To choose the one that meets our needs, we need to consider the following:
4+
45
* do we need eager or lazy evaluation?
56
* do we need to keep the original empty value intact, or modify it in place?
67

7-
## `or()` is chainable, evaluates eagerly, keeps empty value intact
8+
## `or()` is chainable, evaluates eagerly, keeps empty value intact
89

910
`or()`is chainable and eagerly evaluates its argument, as is shown in the following example. Note that because `or`'s arguments are evaluated eagerly, the variable passed to `or` is moved.
1011

@@ -29,7 +30,7 @@ fn main() {
2930
}
3031
```
3132

32-
## `or_else()` is chainable, evaluates lazily, keeps empty value intact
33+
## `or_else()` is chainable, evaluates lazily, keeps empty value intact
3334

3435
Another alternative is to use `or_else`, which is also chainable, and evaluates lazily, as is shown in the following example:
3536

@@ -57,7 +58,7 @@ fn main() {
5758
}
5859
```
5960

60-
## `get_or_insert()` evaluates eagerly, modifies empty value in place
61+
## `get_or_insert()` evaluates eagerly, modifies empty value in place
6162

6263
To make sure that an `Option` contains a value, we can use `get_or_insert` to modify it in place with a fallback value, as is shown in the following example. Note that `get_or_insert` eagerly evaluates its parameter, so variable `apple` is moved:
6364

@@ -78,9 +79,10 @@ fn main() {
7879
}
7980
```
8081

81-
## `get_or_insert_with()` evaluates lazily, modifies empty value in place
82+
## `get_or_insert_with()` evaluates lazily, modifies empty value in place
8283

8384
Instead of explicitly providing a value to fall back on, we can pass a closure to `get_or_insert_with`, as follows:
85+
8486
```rust,editable
8587
#[derive(Debug)]
8688
enum Fruit { Apple, Orange, Banana, Kiwi, Lemon }

src/error/option_unwrap/map.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Combinators: `map`
22

3-
`match` is a valid method for handling `Option`s. However, you may
4-
eventually find heavy usage tedious, especially with operations only valid
5-
with an input. In these cases, [combinators][combinators] can be used to
3+
`match` is a valid method for handling `Option`s. However, you may
4+
eventually find heavy usage tedious, especially with operations only valid
5+
with an input. In these cases, [combinators][combinators] can be used to
66
manage control flow in a modular fashion.
77

8-
`Option` has a built in method called `map()`, a combinator for the simple
9-
mapping of `Some -> Some` and `None -> None`. Multiple `map()` calls can be
8+
`Option` has a built in method called `map()`, a combinator for the simple
9+
mapping of `Some -> Some` and `None -> None`. Multiple `map()` calls can be
1010
chained together for even more flexibility.
1111

1212
In the following example, `process()` replaces all functions previous

src/error/option_unwrap/question_mark.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ function is being executed and return `None`.
77

88
```rust,editable
99
fn next_birthday(current_age: Option<u8>) -> Option<String> {
10-
// If `current_age` is `None`, this returns `None`.
11-
// If `current_age` is `Some`, the inner `u8` value + 1
10+
// If `current_age` is `None`, this returns `None`.
11+
// If `current_age` is `Some`, the inner `u8` value + 1
1212
// gets assigned to `next_age`
1313
let next_age: u8 = current_age? + 1;
1414
Some(format!("Next year I will be {}", next_age))

src/error/result.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ fn main() -> Result<(), ParseIntError> {
7575
}
7676
```
7777

78-
7978
[option]: https://doc.rust-lang.org/std/option/enum.Option.html
8079
[result]: https://doc.rust-lang.org/std/result/enum.Result.html
8180
[parse]: https://doc.rust-lang.org/std/primitive.str.html#method.parse

src/error/result/enter_question_mark.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ fn main() {
6969
}
7070
```
7171

72-
7372
[^]: See [re-enter ?][re_enter_?] for more details.
7473

7574
[re_enter_?]: ../multiple_error_types/reenter_question_mark.md

src/flow_control/let_else.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
# let-else
22

3-
43
> 🛈 stable since: rust 1.65
54
>
65
> 🛈 you can target specific edition by compiling like this
76
> `rustc --edition=2021 main.rs`
87
9-
108
With `let`-`else`, a refutable pattern can match and bind variables
119
in the surrounding scope like a normal `let`, or else diverge (e.g. `break`,
1210
`return`, `panic!`) when the pattern doesn't match.
@@ -58,8 +56,7 @@ patterns with an unfortunate bit of repetition and an outer `let`:
5856

5957
[option][option], [match][match], [if let][if_let] and the [let-else RFC][let_else_rfc].
6058

61-
6259
[match]: ./match.md
6360
[if_let]: ./if_let.md
6461
[let_else_rfc]: https://rust-lang.github.io/rfcs/3137-let-else.html
65-
[option]: ../std/option.md
62+
[option]: ../std/option.md

src/flow_control/loop.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ fn main() {
3333
}
3434
}
3535
}
36-
```
36+
```

src/flow_control/match/binding.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ fn main() {
4747
```
4848

4949
### See also:
50+
5051
[`functions`][functions], [`enums`][enums] and [`Option`][option]
5152

5253
[functions]: ../../fn.md

src/flow_control/match/destructuring.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ A `match` block can destructure items in a variety of ways.
88
* [Destructuring Pointers][refs]
99
* [Destructuring Structures][struct]
1010

11-
1211
[enum]: destructuring/destructure_enum.md
1312
[refs]: destructuring/destructure_pointers.md
1413
[struct]: destructuring/destructure_structures.md

0 commit comments

Comments
 (0)