1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-05-22 02:10:25 +02:00

43 Commits

Author SHA1 Message Date
Nicole L
a4469e7a91
Add division example to expression exercise (#2673) 2025-02-28 10:30:54 -08:00
Eric Githinji
1a64c9ba9a
Use dbg! instead of println! in Day 2. (#2657)
Part of #2478 to clean up code blocks when all that is needed is a
trivial debug print statement.

As mentioned in previous related PRs, in some places I've opted to
retain the use of println! because dbg! makes it less readable.

Co-authored-by: Eric Githinji <egithinji@google.com>
2025-02-25 21:12:06 +00:00
Dustin J. Mitchell
44a79741ff
Be more consistent about tests vs. main (#2644)
The content slides all use `fn main`, with the exception of the testing
segment. But with this change, where it makes sense exercises use tests
instead, and not both tests and `fn main`.

A small change in `book.js` supports running tests when a code sample
does not have `fn main` but does have `#[test]`, so these work
naturally.

Fixes #1581.
2025-02-18 20:13:16 +00:00
Nicole L
699c5137c7
Remove nesting from let else example (#2600) 2025-02-11 10:45:04 -08:00
Nicole L
06bdb40442
Make code in expression evaluation exercise editable (#2601) 2025-02-06 11:00:46 -08:00
Nicole L
553e3c5b10
Add slide reviewing irrefutable patterns (#2608) 2025-02-05 16:16:38 -08:00
Nicole L
28ab749338
Add "More to Explore" section to struct patterns slide (#2604) 2025-02-05 16:12:01 -08:00
Nicole L
afe206beab
Add division example to expression exercise (#2605) 2025-02-05 16:11:42 -08:00
Dustin J. Mitchell
3b7442a498
Split let control flow into mutliple sub-slides (#2567)
There are three kinds of syntax here, making for a very long and
hard-to-navigate slide. Splitting it up helps!
2025-01-22 20:06:53 +01:00
Dustin J. Mitchell
f19bb8f10d
Briefly touch on match ergonomics (#2581)
This is done in the speaker notes as it's a relatively minor point, but
one that students should have in the back of their mind when they
wonder, "hey, how does a `&Foo` match against `Foo` patterns??"
2025-01-22 17:47:23 +01:00
Dustin J. Mitchell
68e1ebd865
Change Expression Evaluation exercise to 15m (#2561)
Fixes #2559.
2025-01-19 01:47:39 -05:00
Dustin J. Mitchell
f1ad41e2bc
Add TODO to indicate let-else example should be rewritten (#2562)
Fixes #2473.
2025-01-19 01:47:33 -05:00
Nicole L
e902b1ef60
Add a slide on match to control flow section (#2515) 2024-12-17 12:08:42 -08:00
Nicole L
2bae363d16
Remove error handling from expression evaluation exercise (#2517)
I think it would be good to simplify the expression evaluation exercise
by removing the error handling around the divide-by-zero case. I think
it overcomplicates the exercise and and adds confusion since at this
point we haven't introduced `Result` (or at least not in any detail).
This allows the students to just focus on writing the pattern matches on
`Expression` and `Op`, and allows the exercise to be shorter (and I
think we need to free up some time where we can, my classes often run
long and cut into how much time students have for exercises).
2024-12-16 16:36:27 -05:00
Moritz Firsching
6148caed7a
Change tests for pattern-matching exercise (#2463)
to catch wrong `right == 0` checks.

To change the number like this catches for example a wrong
implementation only looking if `right_result` is zero, but not checking
if we are doing a division.
2024-11-18 16:11:58 +00:00
Martin Geisler
6e829ff89a
Show expressions trees (#2425)
While giving the class, I noticed that a few people were not used to
this kind of recursive structures. A diagram could help here.
2024-10-28 19:24:22 +01:00
Martin Geisler
8bfff0d95a
Consistently inline formatting arguments (#2413) 2024-10-21 20:01:21 +02:00
Martin Geisler
0474168196
Remove outdated tip about handling division by zero (#2393)
The exercise text already asks you to handle this.
2024-10-02 00:31:49 +00:00
Nicole L
2f9babd098
Miscellaneous minor improvements (#2370) 2024-09-20 14:19:53 -07:00
Frances Wingerter
6d743dac5a
Change let-else example to demonstrate undesirable nesting (#2276)
Fixes #2070.

Previously we showed a forcibly de-nested version using both let and
if-let. this is not a construction that new learners of Rust are likely
to have seen or written, while nesting if-let is closer to patterns that
appear in other languages and better motivates the de-nesting
transformation to let-else
2024-08-13 14:26:52 +00:00
Andrew Walbran
5f4ff0ab09
List expressions which are actually explained on this page (#2115)
`match` expressions were explained on an earlier page.
2024-06-03 10:54:16 -04:00
Manichand Kondapaka
48325a08fe
Updated struct and enums in pattern-matching. (#2021)
#1464 issue.

---------

Co-authored-by: Martin Geisler <martin@geisler.net>
2024-04-30 10:07:10 -04:00
Nicole L
04c28ed641
Simplify if-let example (#1977)
I find that `if let` makes the most sense to use when you don't have an
`else` case, otherwise it's generally clearer to express the same thing
with a `match`. This changes the `if let` example to be (arguably) a bit
more idiomatic and less verbose.
2024-04-12 12:45:01 -04:00
Nicole L
c1e605df25
Rework introduction of pattern matching (#1843) 2024-02-28 11:14:53 -08:00
Dustin J. Mitchell
9f67c9b0e7
Adjust morning-session timings downward (#1786)
Based on feedback from @marshallpierce that mornings took about 2.5
hours, this adjusts a bunch of the morning times downward to try to
match that. In other words, this is trying to make the times in the
course more accurate, rather than reducing the amount of time available
for these slides.

This also updates the `course-schedule` tool to be able to show
per-segment timings.
2024-02-06 15:48:56 -05:00
Pavel Roskin
14dbc99ed0
Clarify that pattern matching consumes enum variant by default (#1663)
Clarify that pattern matching consumes enum variant by default

Describe two ways to borrow the variant without consuming it.

Fixes #1491.
2024-01-08 10:02:43 +01: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
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
Marshall Pierce
6c5061bb90
Various small fixes (#1556)
Plus one more substantial comment on casting.
2023-12-05 18:06:42 -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
Dustin J. Mitchell
6744822454
Minor fixes (#579)
* order the Cat and Dog correctly in the vec

* make example editable

* patterns: capture vs. constant

* clarify notes on indexing a string
2023-04-24 14:46:38 -04:00
Charisee Chiw
59d3d7f625
Indent code in speaker notes (#476)
* Indent code in speaker notes

#475

* Update stack.md

* Update destructuring-arrays.md

* Update hashmap.md

* Update traits.md
2023-03-11 14:12:32 -08:00
Charisee Chiw
8ee637d886
Lecture notes for Destructing Arrays (#266)
* Lecture notes for Destructing Arrays

* Update destructuring-arrays.md
2023-02-22 13:41:12 +01:00
Charisee Chiw
cf931075d5
Update destructuring-arrays.md (#369)
* Update destructuring-arrays.md

* Update destructuring-arrays.md
2023-02-09 13:17:33 -08:00
Marko Zagar
36ce63cb10
Updates and minor fixes to Day 2: Morning (#372) 2023-02-09 21:15:47 +00:00
Charisee Chiw
1835896e58
Speaker notes for destructuring-structs.md (#265)
* Update destructuring-structs.md

* Update destructuring-structs.md
2023-02-07 07:42:57 +00:00
gendx
c3e3dc6020
Add speaker notes for pattern-matching/destructuring-arrays.md (#346) 2023-02-06 17:38:01 +01:00
Andrew Gaul
f33b1f923a
Use f-string in example for consistency (#328)
Also fix typo.
2023-02-03 13:07:29 +00:00
Charisee Chiw
4588d95427 Update match-guards.md 2023-01-26 12:08:21 +00:00
Charisee Chiw
bd3642694b
Update destructuring-enums.md (#261)
* Update destructuring-enums.md

* Update destructuring-enums.md

Following the typesetting and terminology used in https://doc.rust-lang.org/book/ch03-05-control-flow.html and https://doc.rust-lang.org/book/ch06-02-match.html

Co-authored-by: Fabian Bornhofen <fbornhofen@google.com>
2023-01-23 21:20:08 +01:00
Igor Petruk
12c3e2989d
Update match-guards.md (#233)
* Update match-guards.md

Adding more information how match guards are different from simply using "if" inside of the match case, after the case has matched.

* Be consistent about naming of match arms.

Co-authored-by: Andrew Walbran <qwandor@google.com>
2023-01-23 13:09:32 +00:00
Igor Petruk
94ed176761
Update destructuring-enums.md (#231) 2023-01-23 11:40:02 +00:00
Martin Geisler
c212a473ba Publish Comprehensive Rust 🦀 2022-12-21 16:38:28 +01:00