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.
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>
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.
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).
Explain what traits `thiserror::Error` derives.
Explain how `.context()` and `.with_context()` operate on types that are
not aware of `anyhow`.
Resolves#1597.
`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(...)??`.
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>
* 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>
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.
* 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>
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.