1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2024-12-15 14:27:50 +02:00
Commit Graph

1546 Commits

Author SHA1 Message Date
Martin Geisler
c9f66fd425
Format all Markdown files with dprint (#1157)
This is the result of running `dprint fmt` after removing `src/` from
the list of excluded directories.

This also reformats the Rust code: we might want to tweak this a bit in
the future since some of the changes removes the hand-formatting. Of
course, this formatting can be seen as a mis-feature, so maybe this is
good overall.

Thanks to mdbook-i18n-helpers 0.2, the POT file is nearly unchanged
after this, meaning that all existing translations remain valid! A few
messages were changed because of stray whitespace characters:

     msgid ""
     "Slices always borrow from another object. In this example, `a` has to remain "
    -"'alive' (in scope) for at least as long as our slice. "
    +"'alive' (in scope) for at least as long as our slice."
     msgstr ""

The formatting is enforced in CI and we will have to see how annoying
this is in practice for the many contributors. If it becomes annoying,
we should look into fixing dprint/check#11 so that `dprint` can annotate
the lines that need fixing directly, then I think we can consider more
strict formatting checks.

I added more customization to `rustfmt.toml`. This is to better emulate
the dense style used in the course:

- `max_width = 85` allows lines to take up the full width available in
our code blocks (when taking margins and the line numbers into account).
- `wrap_comments = true` ensures that we don't show very long comments
in the code examples. I edited some comments to shorten them and avoid
unnecessary line breaks — please trim other unnecessarily long comments
when you see them! Remember we're writing code for slides 😄
- `use_small_heuristics = "Max"` allows for things like struct literals
and if-statements to take up the full line width configured above.

The formatting settings apply to all our Rust code right now — I think
we could improve this with https://github.com/dprint/dprint/issues/711
which lets us add per-directory `dprint` configuration files. However,
the `inherit: true` setting is not yet implemented (as far as I can
tell), so a nested configuration file will have to copy most or all of
the top-level file.
2023-12-31 00:15:07 +01:00
Andriy Redko
f43e72e0ad
uk: Table of content translation (Rust v2) (#1613)
Table of content translation (Rust v2)

Signed-off-by: Andriy Redko <drreta@gmail.com>
2023-12-27 12:01:24 +00:00
ompugao
897c13ad84
ja: Fix a typo in ja.po (#1612)
Fix a typo in ja.po: "完結" -> "簡潔"
2023-12-25 20:05:07 +09:00
Lukasz Anforowicz
dea36b76cf
Chromium: Add a section about the chromium::import! macro. (#1611) 2023-12-22 07:50:11 -08:00
Ibrahim Ahmad (feyroozecode)
e1d98521bb
Update match.md (#1595)
correct a little errors

---------

Co-authored-by: Dustin J. Mitchell <dustin@v.igoro.us>
2023-12-21 15:50:02 +00:00
Martin Geisler
a99a86dc50
Update all dependencies (#1610)
This resolves a few Dependabot alerts on `zerocopy` and refreshes the
other direct dependencies.
2023-12-21 13:55:45 +00:00
Martin Geisler
6c84b0aaf4
da: Translations for the other resources page (#1488) 2023-12-21 13:36:59 +00:00
Ning Chen
2fc3ddc34d
Add adb root for service deployment (#1550)
Otherwise
```
$ adb shell /data/local/tmp/birthday_server
thread 'main' panicked at birthday_service/src/server.rs:16:10:
Failed to register service: PERMISSION_DENIED
```
2023-12-21 14:29:18 +01:00
Ning Chen
01b4b28ff8
Link statically to avoid dynamic link error (#1544)
```
$ adb shell /data/local/tmp/hello_rust_with_dep
CANNOT LINK EXECUTABLE "/data/local/tmp/hello_rust_with_dep": library "libtextwrap.dylib.so" not found: needed by main executable
```
2023-12-21 14:27:14 +01:00
Ning Chen
a9eaa129cf
Add safety comment (#1553)
```
error: unsafe block missing a safety comment
  --> interoperability/bindgen/main.rs:11:5
   |
11 |     unsafe {
   |     ^^^^^^^^
   |
   = help: consider adding a safety comment on the preceding line
   = help: for further information visit https://rust-lang.github.io/rust-clippy
/master/index.html#undocumented_unsafe_blocks
   = note: requested on the command line with `-D clippy::undocumented-unsafe-bl
ocks`
```
2023-12-21 14:26:25 +01:00
Pavel Roskin
30f8e50b43
Fix typos (#1608) 2023-12-20 18:21:54 +00:00
Pavel Roskin
cf81b7a88d
Swap Err and OtherErr, it's Err that must implement From (#1596)
It's clear from the above text and example that the error type returned
by the outer function (`Err` in this case) must implement the `From`
trait to accept the error returned by the inner function (`OtherErr` in
this case).
2023-12-20 15:51:20 +00:00
Martin Huschenbett
568e78a5b0
Remove two unnecessary muts from the Rc example (#1603)
Neither `a` nor `b` need to be mutable in this example. Hence, I removed
them.
2023-12-20 10:47:35 -05:00
Martin Huschenbett
a369e108fc
Let BinaryTreeL::has take a reference (#1607)
Currently, `BinaryTree::has` takes its argument by value. This is a
pretty unrealistic API for a Rust library. Let's fix this and take the
argument by reference instead.
2023-12-20 10:44:33 -05:00
Martin Huschenbett
dce30e0e49
Make protobuf exercise slightly easier (#1605)
As @djmitche suggested in

https://github.com/google/comprehensive-rust/pull/1591#pullrequestreview-1782012715
it might be a little easier for the students if we give them a prefix of
the code required for `parse_field`. That's exactly what we do here.
2023-12-20 10:43:47 -05:00
Martin Huschenbett
8e4bb60023
Remove Copy bound from binary tree exercise (#1606)
There's absolutely no need for the element type of the binary tree to be
`Copy`. Let's remove this bound hence.
2023-12-20 10:41:56 -05:00
Martin Huschenbett
52bfb0c4a3
Fix a comment in the protobuf example (#1604)
In https://github.com/google/comprehensive-rust/pull/1591, I changed the
implementation of the protobuf example significantly. However, I forgot
to update a comment which is referred to the old style of
implementation. I'll this slip here.
2023-12-20 10:40:26 -05:00
Martin Huschenbett
0f0596da9d
Add directory tree to mod exercise solution (#1602)
The solution to the modules exercise comes with a bunch of files. I
think it would help the students to get a quick overview of the
directory structure we've chosen first.
2023-12-20 10:39:48 -05:00
Pavel Roskin
e60f56e8f2
Expand "thiserror and anyhow" slide (#1600)
Explain what traits `thiserror::Error` derives.

Explain how `.context()` and `.with_context()` operate on types that are
not aware of `anyhow`.

Resolves #1597.
2023-12-20 15:37:22 +00:00
Martin Huschenbett
26c088497f
Add missing mod declarations to modules solutions (#1601)
The solution for the modules exercise does not work since it is missing
a a few module declarations. Here, we add them.
2023-12-20 10:34:39 -05:00
Grzegorz Milka
c0dfd54f2c
fix: change "widley" to "widely" (#1599)
Co-authored-by: Dustin J. Mitchell <djmitche@google.com>
2023-12-19 14:41:51 +00:00
Andriy Redko
75145070de
uk: Regenerate translation for Comprehensive Rust v2 (#1598)
uk: Regenerate translation for Comprehensive Rust v2

Signed-off-by: Andriy Redko <drreta@gmail.com>
2023-12-19 13:19:22 +00:00
Martin Huschenbett
a35841992e
Simplify some code in the parsing exercise (#1594)
`let Some(x) = E else { return None; }` is equivalent to
`let Some(x) = E?`. That latter is shorter and more idiomatic, so let's
use that.

A pattern of the form `c @ P1 | c @ P1` has the disadvantage that the
name `c` is repeated. Let's replace it with `c @ (P1 | P2)`.

An `x: Option<Result<T, E>>` can be handled more succinctly with
`x.ok_or(...)??`.
2023-12-18 10:03:10 -05:00
Amin Sharifi
9a6a16e4ee
fa: Translate Part 6.x, 7, .., 15.x, 16.1 , .. , 16.5 (#1453)
Part of #671
- Translate Part  `6.x`, `7`, `..`, `15.x`, `16.1` , `..` , `16.5`
2023-12-17 14:14:53 +03:30
Chayim Refael Friedman
61f3e5fb51
Add explanation about when you should use each of the Fn* traits (#1579)
Beginners are confused by this often.

---------

Co-authored-by: Dustin J. Mitchell <dustin@v.igoro.us>
2023-12-15 15:22:59 +00:00
Martin Huschenbett
97a47cab78
Parse into data structures in protobuf example (#1591)
This is a suggestion for how we could make the protobuf exercise at the
end of day 3 better.

Generally speaking, the idea is to parse the protbuf bytes into data
types instead of only printing the parsing outcome to the console. To
make this a little more realistic, we also introduce a trait
`ProtoMessage` for message types.

I think this is more instructive than the current example. In
particular, we get to mess around with lifetimes. This might be a little
more complicated but can be a great opportunity for the students to tie
together different things they've learnt in the course so far.

What do you all think?
2023-12-15 10:00:50 -05:00
Dustin J. Mitchell
085cbf2c1e
Update expression-evaluation exercise: more patterns, more enums (#1582)
This modifies the exercise to lean more into interesting `match`
statements. It also uses the standard `Result` type, based on feedback
that students could understand it sufficiently at this point in the
course.

Addresses #1565.
2023-12-14 15:22:28 +00:00
Martin Huschenbett
302a03bbe3
Remove unnecessary syntax in protobuf example (#1592)
`Ok(x?)` has the same outcome as `x` and save an unpacking/repacking
cycle.

`x as usize` has no effect when `x` already has type `usize`.

In `x < 4usize` the `usize` is unnecessary when `x` already has type
`usize`.
2023-12-14 16:02:40 +01:00
rickyclarkson
c7a86ca584
Fixing a typo (#1588) 2023-12-13 18:26:34 -05:00
Dustin J. Mitchell
afea94b1ed
Use a type alias in binary tree exercise (#1589)
As suggested by @marshallpierce and @hurryabit
2023-12-13 19:53:35 +00:00
Martin Huschenbett
c6973018c6
Fix typo in lifetime annotations section (#1590)
The code example was meant to be `editable` but was marked as
`eitable`.
2023-12-13 13:41:32 -05:00
Martin Huschenbett
ee826ef742
Use cmp + match in binary tree example (#1587)
Currently, the implementation uses if-then-else chains and `<` and `>`.
This is not the most idiomatic Rust. Instead, we can use `cmp` and
`match` to make the code easier to read.

---------

Co-authored-by: Dustin J. Mitchell <djmitche@google.com>
2023-12-13 13:39:23 -05:00
Martin Huschenbett
f37aeac3ca
Remove unnecessary ref mut in binary tree exercise (#1586)
There's no need for the `ref mut` in the pattern. So, let's just drop
it for the sake of simplicity.
2023-12-13 12:34:18 -05:00
Martin Huschenbett
ce081b12f9
Rename test module into tests in smart pointer exercise (#1585)
If I'm not mistaken, the naming convention for modules containing only
tests is to call them `tests` (rather than `test`).
2023-12-13 12:33:31 -05:00
Dustin J. Mitchell
9563f055e2
Minor updates based on instruction (#1583)
This contains some minor updates from #1565.

---------

Co-authored-by: Marshall Pierce <575695+marshallpierce@users.noreply.github.com>
2023-12-13 12:51:34 +00:00
Martin Geisler
35442ad424
Add back apt update (#1584)
This reverts #1490 due to errors seen in
https://github.com/google/comprehensive-rust/actions/runs/7188648811/job/19590765217.
The error says

Get:23 http://azure.archive.ubuntu.com/ubuntu jammy/main amd64
libc6-dev-arm64-cross all 2.35-0ubuntu1cross3 [1546 kB]
    Fetched 41.7 MB in 1s (46.1 MB/s)
E: Failed to fetch
mirror+file:/etc/apt/apt-mirrors.txt/pool/main/b/binutils/binutils-aarch64-linux-gnu_2.38-4ubuntu2.3_amd64.deb
404 Not Found [IP: 52.147.219.192 80]
E: Unable to fetch some archives, maybe run apt-get update or try with
--fix-missing?
    Error: Process completed with exit code 100.

This seems less transient than the error which made us remove the `apt
update` calls in #1490.
2023-12-13 11:33:54 +01:00
Chayim Refael Friedman
86289b4814
Remove an incorrect note (#1580)
People are often confused by this: the fact that we can remove the `*`
in the `println!()` is not because the compiler auto-derefs here (it
does not), but because `Display` is implemented for `&T where T:
Display` (a blanket implementation).
2023-12-12 11:29:50 -05:00
Chayim Refael Friedman
c342a74b3e
Having a Vec allows accessing mutating slice methods, too (#1578)
I don't know why "read-only" was added.
2023-12-12 10:02:10 -05:00
Hidenori Kobayashi
9c5865d8ca
ja: translate Ch. 54 (#1573)
Part of #652.
2023-12-12 21:33:08 +09:00
Marshall Pierce
e41ab44a38
More tiny fixes (#1577) 2023-12-11 16:13:54 -05:00
Dustin J. Mitchell
e765159be1
Clarify completion condition for elevator exercise (#1574)
Addresses the first part of #1565.
2023-12-11 19:12:40 +00:00
Lukasz Anforowicz
f04e277744
Chromium: Add redox_syscall to speaker notes for the third-party exercise. (#1571)
Speaker notes for Chromium's third-party crate exercise list the
transitive dependencies that will be downloaded during the exercise.
Before this commit the list was missing the `redox_syscall` crate.

Additionally, the commit sorts the crates to make it easier to compare
with the output of `git status` or `ls`.

---------

Co-authored-by: Martin Geisler <martin@geisler.net>
2023-12-11 07:21:53 -08:00
AdrienBaudemont
395d58d7ce
fr: running msgmerge on fr.po (update from the English main text). (#1435)
fr: running msgmerge on fr.po (update from the English main text).
2023-12-11 09:44:32 -05:00
Kanta Yamaoka (山岡幹太)
d62f2c4583
Add trait bounds to glossary (#1569)
Hi, this is a tiny MR to add glossary entry for "trait bound". Could you
someone review it? I'm open to suggeston, too. Thank you!
Context:
https://github.com/google/comprehensive-rust/pull/1436#discussion_r1394298992
2023-12-10 17:05:11 +01:00
Adrian Taylor
4a576fd436
Update depending-on-a-crate.md (#1570)
Fix typo
2023-12-08 07:07:13 -08:00
Lukasz Anforowicz
89b41555eb
Title-casing in section titles (#1557)
Fixes https://github.com/google/comprehensive-rust/issues/1552
2023-12-07 18:06:18 -08:00
Martin Geisler
1ec2e8db9e
Expand "Docs" plus light copy-editing (#1568)
I don't like shortening words, so I prefer "Documentation" over "Docs".
I find this less jargony and thus easier to read (and potentially also
easier to translate).
2023-12-07 20:04:36 +00:00
ternbusty
45a8ec4e78
ja: Normalize by running through mdbook-i18n-normalize 0.3.0 (#1482)
Hello, JA translation team!
(https://github.com/google/comprehensive-rust/issues/652)

As part of #1460, I normalized ja.po using mdbook-i18n-normalize 0.3.0.

Steps taken: `mdbook-i18n-normalize`.

I'm open to any feedback or suggestions. Thank you in advance!
2023-12-07 17:23:23 +01:00
Martin Geisler
c080de8253
Simplify enums a little (#1566)
This takes out the huge example with lots of macro magic. I don't think
we need it for an introductory course.

I also cleaned up the formatting a little and made sure to distinguish
between types and values.

---------

Co-authored-by: Dustin J. Mitchell <djmitche@google.com>
2023-12-07 16:15:57 +00:00
Martin Geisler
fca968651e
Fix mdbook redirection table (#1567)
There must have been a merge conflict at some point which resulted in a
malformed table. The result was that most redirects were blindly ignored
by `mdbook`.

I noticed it for
https://google.github.io/comprehensive-rust/enums.html which stopped
working because of this.

I took out the memory management redirect since we already have a file
where redirect would be (`mdbook` helpfully emits an error in this
case).
2023-12-07 15:51:42 +00:00