Skip to content

Commit f37517b

Browse files
woojunromarcoowdrguildoLucaBoschettoiacri
authored
[2025-01-02] Sync fork (#2)
* use OpenSans as fallback font on PRs from forks * Fix typo * Update reference from Rustonomicon to Rust Reference The exercise refers to the "Data layout" section of the Rustonomicon, but now that section claims itself deprecated and redirects to the "Type layout" section of The Rust Reference. * 05_ticket_v2 outro: correct comment on title (mainmatter#179) Characters was meant to be bytes, this was missed in a former refactoring * Change docstring: "when converted to `u8`" Fixed docstring * exercises 02_basic_calculator/04_panics: fix comma splice in panic message * Update 08_overflow.md if you read threw the profile docs it provides 4 profiles. https://doc.rust-lang.org/cargo/reference/profiles.html * chore(ci): re-create book artifacts at the beginning of each month * Update 08_overflow.md Added some context. * Update 11_clone.md (mainmatter#205) typo in code * format * debug pandoc build * fix reference to fallback font * switch off Pandoc verbosity * run Gravity on online PDF * debug * fix a superfluous word in a comment (mainmatter#217) * fix a small typo in 11_locks.md (mainmatter#219) * Fix typo in 03_leak.md (mainmatter#220) Corrected a confusing sentence with double negative. * Add install steps to the welcome page (mainmatter#196) * Warn about the risks of using catch-all patterns (mainmatter#200) * doc: update book 06_01_arrays (mainmatter#195) * Update aliases * Update redirects * Formatting * Link to the next tutored session in the methodology section * Ignore dead code warnings until visibility has been explained (mainmatter#232) * Format all manifests * Don't mark Rust code snippets as runnable * Showcase else-if (mainmatter#234) * Give a more structure hint for iteration exercises (mainmatter#235) * Clarify that both crate and super are keywords (mainmatter#236) * Clarify Send-Sync relationship (mainmatter#237) * Change if-else exercise to require an if-else (mainmatter#238) * Avoid using a suffix (mainmatter#239) --------- Co-authored-by: Marco Otte-Witte <marco.otte-witte@mainmatter.com> Co-authored-by: Simon Morgan <sjm@sjm.io> Co-authored-by: Luca Boschetto <61137723+LucaBoschetto@users.noreply.github.com> Co-authored-by: iacri <49108209+iacri@users.noreply.github.com> Co-authored-by: Henk Oordt <hd@oordt.dev> Co-authored-by: Benjamin Tamasi <half2me@users.noreply.github.com> Co-authored-by: Vincent Ging Ho Yim <cenviity@gmail.com> Co-authored-by: Manuel Bichler <bichler@gmail.com> Co-authored-by: Bartlomiej Dudzik <bartholomew.dudzik@gmail.com> Co-authored-by: Robertino <48034748+rober-m@users.noreply.github.com> Co-authored-by: dawe <dawedawe@posteo.de> Co-authored-by: Will Bush <git@willbush.dev> Co-authored-by: Daniel Wagner-Hall <dawagner@gmail.com> Co-authored-by: Maor Levy <Atixx@users.noreply.github.com> Co-authored-by: LukeMathWalker <20745048+LukeMathWalker@users.noreply.github.com>
1 parent 979bf7b commit f37517b

File tree

34 files changed

+234
-26
lines changed

34 files changed

+234
-26
lines changed

.github/workflows/ci.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,23 @@ jobs:
146146
- run: |
147147
git diff --exit-code site/_redirects
148148
149+
gravity:
150+
runs-on: ubuntu-latest
151+
needs: [build]
152+
steps:
153+
- uses: actions/download-artifact@v4
154+
with:
155+
path: book
156+
pattern: online-pdf
157+
- uses: pnpm/action-setup@v4
158+
with:
159+
version: 9
160+
- run: ls -las ./book
161+
- name: Run Gravity
162+
run: pnpm dlx @gravityci/cli "./book/**/*"
163+
env:
164+
GRAVITY_TOKEN: ${{ secrets.GRAVITY_TOKEN }}
165+
149166
formatter:
150167
runs-on: ubuntu-latest
151168
steps:

book/book.toml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ after = ["exercise-linker"]
1818
[output.html]
1919
git-repository-url = "https://github.com/mainmatter/100-exercises-to-learn-rust"
2020

21+
[output.html.playground]
22+
runnable = false
23+
2124
[output.pandoc]
2225
optional = true
2326
hosted-html = "https://rust-exercises.com/100-exercises/"
@@ -49,8 +52,8 @@ sansfontoptions = [
4952
]
5053
# You can get these fonts here: https://fonts.google.com/selection?query=noto+color+
5154
monofont = "Noto Sans Mono"
52-
mainfontfallback = ["Open Sans"]
53-
sansfontfallback = ["Open Sans"]
55+
mainfontfallback = ["Open Sans:style=Regular"]
56+
sansfontfallback = ["Open Sans:style=Regular"]
5457
monofontfallback = [
5558
"Noto Color Emoji:mode=harf",
5659
]
@@ -90,8 +93,8 @@ sansfontoptions = [
9093
]
9194
# You can get these fonts here: https://fonts.google.com/selection?query=noto+color+
9295
monofont = "Noto Sans Mono"
93-
mainfontfallback = ["Open Sans"]
94-
sansfontfallback = ["Open Sans"]
96+
mainfontfallback = ["Open Sans:style=Regular"]
97+
sansfontfallback = ["Open Sans:style=Regular"]
9598
monofontfallback = [
9699
"Noto Color Emoji:mode=harf",
97100
]
@@ -121,8 +124,8 @@ metadata-file = "metadata.yml"
121124
[output.pandoc.profile.html.variables]
122125
# You can get these fonts here: https://fonts.google.com/selection?query=noto+color+
123126
monofont = "Noto Sans Mono"
124-
mainfontfallback = ["Open Sans"]
125-
sansfontfallback = ["Open Sans"]
127+
mainfontfallback = ["Open Sans:style=Regular"]
128+
sansfontfallback = ["Open Sans:style=Regular"]
126129
monofontfallback = [
127130
"Noto Color Emoji:mode=harf",
128131
]

book/link2alias.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"https://blog.acolyer.org/2019/05/28/cheri-abi/": "f2u",
3+
"https://code.visualstudio.com": "f6c",
34
"https://crates.io": "f4q",
45
"https://crates.io/crates/cargo-modules": "f2n",
56
"https://doc.rust-lang.org/book/ch03-02-data-types.html#integer-types": "ffr",
@@ -164,6 +165,7 @@
164165
"https://mainmatter.com/contact/": "ff2",
165166
"https://mainmatter.com/rust-consulting/": "fff",
166167
"https://marabos.nl/atomics/": "fxg",
168+
"https://marketplace.visualstudio.com/items?itemName=matklad.rust-analyzer": "f6a",
167169
"https://nostarch.com/rust-rustaceans": "f6p",
168170
"https://owasp.org/www-community/vulnerabilities/Doubly_freeing_memory": "f2k",
169171
"https://owasp.org/www-community/vulnerabilities/Using_freed_memory": "f2s",
@@ -177,14 +179,17 @@
177179
"https://rust-lang.github.io/api-guidelines/naming.html#casing-conforms-to-rfc-430-c-case": "fze",
178180
"https://rust-lang.github.io/wg-async/vision/submitted_stories/status_quo/barbara_battles_buffered_streams.html": "f6w",
179181
"https://ryhl.io/blog/async-what-is-blocking/": "f6v",
182+
"https://ti.to/mainmatter/rust-from-scratch-jan-2025": "fvf",
180183
"https://tokio.rs/tokio/tutorial/select": "f6n",
181184
"https://valgrind.org/docs/manual/dh-manual.html": "f2t",
182185
"https://veykril.github.io/tlborm/": "fz5",
183186
"https://without.boats/blog/the-scoped-task-trilemma/": "f67",
184187
"https://www.amazon.com/dp/B0DJ14KQQG/": "f6g",
188+
"https://www.jetbrains.com/rust/": "f6d",
185189
"https://www.lpalmieri.com/": "ffv",
186190
"https://www.lpalmieri.com/posts/2020-12-11-zero-to-production-6-domain-modelling/": "f4t",
187191
"https://www.oreilly.com/library/view/programming-rust-2nd/9781492052586/": "f6y",
192+
"https://www.rust-lang.org/tools/install": "f6j",
188193
"https://www.youtube.com/playlist?list=PLqbS7AVVErFirH9armw8yXlE6dacF-A6z": "f6l",
189194
"https://zero2prod.com": "ff8"
190195
}

book/src/01_intro/00_welcome.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ It has been designed to be interactive and hands-on.
2424
to be delivered in a classroom setting, over 4 days: each attendee advances
2525
through the lessons at their own pace, with an experienced instructor providing
2626
guidance, answering questions and diving deeper into the topics as needed.\
27-
If you're interested in attending one of our training sessions, or if you'd like to
28-
bring this course to your company, please [get in touch](https://mainmatter.com/contact/).
27+
You can sign up for the next tutored session on [our website](https://ti.to/mainmatter/rust-from-scratch-jan-2025).
28+
If you'd like to organise a private session for your company, please [get in touch](https://mainmatter.com/contact/).
2929

30-
You can also follow the course on your own, but we recommend you find a friend or
30+
You can also take the courses on your own, but we recommend you find a friend or
3131
a mentor to help you along the way should you get stuck. You can
32-
also find solutions to all exercises in the
32+
find solutions for all exercises in the
3333
[`solutions` branch of the GitHub repository](https://github.com/mainmatter/100-exercises-to-learn-rust/tree/solutions).
3434

3535
## Formats
@@ -67,9 +67,18 @@ Each exercise is structured as a Rust package.
6767
The package contains the exercise itself, instructions on what to do (in `src/lib.rs`), and a test suite to
6868
automatically verify your solution.
6969

70-
### `wr`, the workshop runner
70+
### Tools
7171

72-
To verify your solutions, we've provided a tool that will guide you through the course.
72+
To work through this course, you'll need:
73+
74+
- [**Rust**](https://www.rust-lang.org/tools/install)).
75+
If `rustup` is already installed on your system, run `rustup update` (or another appropriate command depending on how you installed Rust on your system) to ensure you're running on the latest stable version.
76+
- _(Optional but recommended)_ An IDE with Rust autocompletion support.
77+
We recommend one of the following:
78+
- [RustRover](https://www.jetbrains.com/rust/);
79+
- [Visual Studio Code](https://code.visualstudio.com) with the [`rust-analyzer`](https://marketplace.visualstudio.com/items?itemName=matklad.rust-analyzer) extension.
80+
81+
To verify your solutions, we've also provided a tool to guide you through the course.
7382
It is the `wr` CLI (short for "workshop runner").
7483
Install it with:
7584

book/src/02_basic_calculator/03_if_else.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,38 @@ if number < 5 {
3636
}
3737
```
3838

39+
### `else if` clauses
40+
41+
Your code drifts more and more to the right when you have multiple `if` expressions, one nested inside the other.
42+
43+
```rust
44+
let number = 3;
45+
46+
if number < 5 {
47+
println!("`number` is smaller than 5");
48+
} else {
49+
if number >= 3 {
50+
println!("`number` is greater than or equal to 3, but smaller than 5");
51+
} else {
52+
println!("`number` is smaller than 3");
53+
}
54+
}
55+
```
56+
57+
You can use the `else if` keyword to combine multiple `if` expressions into a single one:
58+
59+
```rust
60+
let number = 3;
61+
62+
if number < 5 {
63+
println!("`number` is smaller than 5");
64+
} else if number >= 3 {
65+
println!("`number` is greater than or equal to 3, but smaller than 5");
66+
} else {
67+
println!("`number` is smaller than 3");
68+
}
69+
```
70+
3971
## Booleans
4072

4173
The condition in an `if` expression must be of type `bool`, a **boolean**.\

book/src/02_basic_calculator/08_overflow.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ The `bench` profile is the default profile used by `cargo bench`. The `bench` pr
8080
Use `dev` for iterative development and debugging, `release` for optimized production builds,\
8181
`test` for correctness testing, and `bench` for performance benchmarking.
8282

83-
84-
8583
> "Have you built your project in release mode?" is almost a meme in the Rust community.\
8684
> It refers to developers who are not familiar with Rust and complain about its performance on
8785
> social media (e.g. Reddit, Twitter, etc.) before realizing they haven't built their project in

book/src/03_ticket_v1/03_modules.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ You can compose the path in various ways:
8585
- starting from the parent module, e.g. `super::my_function`
8686
- starting from the current module, e.g. `sub_module_1::MyStruct`
8787

88+
Both `crate` and `super` are **keywords**.\
89+
`crate` refers to the root of the current crate, while `super` refers to the parent of the current module.
90+
8891
Having to write the full path every time you want to refer to a type can be cumbersome.
8992
To make your life easier, you can introduce a `use` statement to bring the entity into scope.
9093

book/src/04_traits/11_clone.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ that to `consumer` instead.\
5656
## In memory
5757

5858
Let's look at what happened in memory in the example above.
59-
When `let mut s: String::from("hello");` is executed, the memory looks like this:
59+
When `let mut s = String::from("hello");` is executed, the memory looks like this:
6060

6161
```text
6262
s

book/src/05_ticket_v2/02_match.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,11 @@ match status {
6868
```
6969

7070
The `_` pattern matches anything that wasn't matched by the previous patterns.
71+
72+
<div class="warning">
73+
By using this catch-all pattern, you _won't_ get the benefits of compiler-driven refactoring.\
74+
If you add a new enum variant, the compiler _won't_ tell you that you're not handling it.
75+
76+
If you're keen on correctness, avoid using catch-alls. Leverage the compiler to re-examine all matching sites and determine how new enum variants should be handled.
77+
78+
</div>

book/src/06_ticket_management/01_arrays.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ let numbers: [u32; 3] = [1, 2, 3];
2121
This creates an array of 3 integers, initialized with the values `1`, `2`, and `3`.\
2222
The type of the array is `[u32; 3]`, which reads as "an array of `u32`s with a length of 3".
2323

24+
If all array elements are the same, you can use a shorter syntax to initialize it:
25+
26+
```rust
27+
// [ <value> ; <number of elements> ]
28+
let numbers: [u32; 3] = [1; 3];
29+
```
30+
31+
`[1; 3]` creates an array of three elements, all equal to `1`.
32+
2433
### Accessing elements
2534

2635
You can access elements of an array using square brackets:

0 commit comments

Comments
 (0)