1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-03-20 22:36:03 +02:00

41 Commits

Author SHA1 Message Date
Nicole L
9023dd9caa
Tweak timings of exercises to better reflect teaching times (#1839)
A few of the early exercises had much larger estimates than were
actually necessary for the super simple early exercises. I've gone
through and reviewed the time estimates for exercises and tweaked the
estimates based on how much time students have actually needed in my
classes so far.
2024-02-22 10:21:39 -05:00
IP1llar
2e2d47c709
Update try.md - syntax error (#1807)
Add second `:`
2024-02-12 09:39:40 -05:00
Yuri Astrakhan
1dfc9f2e33
Clarify usage for thiserror-and-anyhow (#1724)
IMO it is better to explain to users the common usage / applicability
domain for anyhow and thiserror crates

---------

Co-authored-by: Dustin J. Mitchell <djmitche@google.com>
2024-01-18 15:28:00 -05:00
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
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
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
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
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
Marshall Pierce
9efad3212f
More minor fixes (#1561)
- Fix compile errors and warnings in error handling example
- Tweak iteration example so that it correctly visits the first grid
coordinate
2023-12-06 12:53:06 -05:00
Dustin J. Mitchell
6d19292f16
Comprehensive Rust v2 (#1073)
I've taken some work by @fw-immunant and others on the new organization
of the course and condensed it into a form amenable to a text editor and
some computational analysis. You can see the inputs in `course.py` but
the interesting bits are the output: `outline.md` and `slides.md`.

The idea is to break the course into more, smaller segments with
exercises at the ends and breaks in between. So `outline.md` lists the
segments, their duration, and sums those durations up per-day. It shows
we're about an hour too long right now! There are more details of the
segments in `slides.md`, or you can see mostly the same stuff in
`course.py`.

This now contains all of the content from the v1 course, ensuring both
that we've covered everything and that we'll have somewhere to redirect
every page.

Fixes #1082.
Fixes #1465.

---------

Co-authored-by: Nicole LeGare <dlegare.1001@gmail.com>
Co-authored-by: Martin Geisler <mgeisler@google.com>
2023-11-29 16:39:24 +01:00
justanotheranonymoususer
17f61463f5
Update converting-error-types.md (#1428) 2023-10-25 11:02:34 -04:00
Manish Kumar
358d7da22c
Update catch_unwind example (#1356)
Fixes #1352.

---------

Co-authored-by: Martin Geisler <martin@geisler.net>
2023-10-12 15:27:45 +00:00
sakex
f79e6726cc
Add that the ? operator works with From<Err> (#1059) 2023-08-09 16:48:15 +02:00
sakex
98be9e149c
Talk about options in ? chapter (#600)
* Talk about options in `?` chapter

* Combine Option and Result examples

* Update try-operator.md

* Remove semicolon from expansion

* Focus on expansion of `expr?`

* Update try-operator.md

* Update try-operator.md

---------

Co-authored-by: Martin Geisler <mgeisler@google.com>
2023-07-28 13:48:58 +02:00
Dominik Maier
46a38bc67a
Error is not yet available in core on stable (#1005) 2023-07-18 11:02:24 +02:00
Martin Geisler
bd98a829c6
Fix typo in try-operator.md (#916) 2023-07-06 15:25:37 +01:00
Martin Geisler
aba7fd7f56
Simplify error handling pages (#851)
This makes the `use` statements more consistent and shortens some
variable names.
2023-06-22 16:27:06 +02:00
Andrew Walbran
c1ad97c659
Fix example to build and run (#838) 2023-06-21 09:48:05 +01:00
Martin Geisler
6ade739651
Ensure code blocks are editable (#597)
We should default to making code blocks editable: this ensures
consistent syntax highlighting (see #343) and it allows the instructor
to freely edit anything they want.
2023-04-27 23:45:41 +02:00
Martin Geisler
c0d03bd86b
Consistently use err for the error value (#599) 2023-04-27 19:10:49 +02:00
Yuri Astrakhan
5cdb73387f
Inline format vars to make the format str simpler (#551) 2023-04-06 12:00:10 +02:00
Andrew Walbran
7a22d5567a
Don't allocate in success case (#506)
`format!` was being called (and allocating a string) even in the success case.
2023-03-15 09:06:35 +01:00
Andrew Walbran
1be641203e
Split out example to separate page. (#319)
The example is quite long and so the page didn't easily fit on the
same screen as the explanation
2023-02-03 10:12:31 +00:00
Andrew Walbran
27b6165202 Implement Error. 2023-01-27 17:54:37 +00:00
Andrew Walbran
caaca140ca Another note for anyhow. 2023-01-27 17:54:37 +00:00
Andrew Walbran
79f5f0dade Add slide about Box<dyn Error> before introducing anyhow. 2023-01-27 17:54:37 +00:00
Andrew Walbran
e5c97e12cb No need for thiserror as well as anyhow. 2023-01-27 17:54:37 +00:00
Andrew Walbran
9fa0e89e90 It makes no sense to use both return and ?. 2023-01-27 17:54:37 +00:00
Andrew Walbran
52d28b155b Mention std::error::Error in speaker notes, and other useful traits. 2023-01-27 17:54:37 +00:00
Igor Petruk
617f4e2bb7
Update error-contexts.md (#251)
* Update error-contexts.md

Adding more speaker notes about `anyhow`.

* Add markup

Co-authored-by: Martin Geisler <martin@geisler.net>
2023-01-24 07:33:03 +00:00
Igor Petruk
543cad59e4
Update result.md (#250)
* Update result.md

Adding a speaker note that `Result` documentation is a recommended read.

* Adding a note why `Result` encourages error checking.

* Wordsmithing

Co-authored-by: Andrew Walbran <qwandor@google.com>
2023-01-23 13:47:41 +00:00
Andy George
492037641e
fix Cargo.toml syntax (#190) 2023-01-20 11:28:38 +01:00
Ilya Grigoriev
acdf00ae6e Add speaker notes about error examples 2023-01-11 18:14:58 -08:00
Ilya Grigoriev
68eed5b4f2
Error handling: clarify printing of Result
Two examples may print either `Ok(username)` or `Err(error)`.
This commit clarifies this fact.
2023-01-06 12:35:05 -08:00
Martin Geisler
9a68434cac
Merge pull request #49 from ilyagr/patch-1
`anyhow`: Remove `ReadUsernameError::IoError`
2023-01-05 15:57:17 +01:00
Arman Yessenamanov
e1c670c4a8
Fix a typo in result.md
"have already see" -> "have already seen"
2023-01-05 14:41:40 +06:00
liao02x
8d36a3bdd3
fix typo in deriving-error-enums.md 2023-01-03 21:18:30 -08:00
Martin Geisler
c15e84f63e
More precise phrasing of what ? expands to
As per the suggestion from @QuineDot in #65.
2022-12-27 18:09:54 +01:00
Ilya Grigoriev
5ce7a08f0e
anyhow: say this example has fewer custom types 2022-12-23 13:35:40 -08:00
Ilya Grigoriev
894e694cdb
anyhow: Remove ReadUsernameError::IoError
As far as I understand, the example with the `anyhow` example
does not use its special `IoError` anymore, unlike the previous
example with just `thiserror`.

I think this should be made clear. I considered just adding a
`// Now unused` comment, but I think ti's clearer to just remove
the unused code.
2022-12-23 13:32:03 -08:00
Martin Geisler
c212a473ba Publish Comprehensive Rust 🦀 2022-12-21 16:38:28 +01:00