1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-05-18 16:33:09 +02:00

1367 Commits

Author SHA1 Message Date
Nicole L
5f6b9333fa
Add Android.bp entries for googletest and mockall example tests (#2643) 2025-02-26 09:11:48 -08:00
Nicole L
4ee2337c63
Add missing static_libs dep for libbirthday example (#2640) 2025-02-26 09:07:36 -08:00
Nicole L
7f8596e9bc
Use jni_libs for JNI dependency (#2637) 2025-02-26 09:06:09 -08:00
Nicole L
a10b4e6e21
Reorder CXX build steps to show genrules first (#2642) 2025-02-26 09:05:36 -08:00
Dustin J. Mitchell
08c613326a
Remove confusing speaker note from Shared-References slide (#2659)
Dangling references are discussed later in the "Borrowing" segment.

Fixes #2656
2025-02-26 11:48:54 -05: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
scubed2
32a8b4bf13
Use chopsticks and limit philosophers. (#2655)
Use chopstick to explain why 2 are needed to eat.
Limit async to 2 philosophers so they can deadlock in tokio.
(Tested with [3, 4, 5] philosophers and they all were able to run
without deadlock
with lock ordering disabled.)

---------

Co-authored-by: Sterling Stein <scubed2+git@gmail.com>
2025-02-24 16:13:16 +00:00
Eric Githinji
f531d4dfd7
Use dbg! instead of println! in Day 1 aft session (#2654)
Part of #2478 to clean up code blocks when all that is needed is a
trivial debug print statement.

In certain slides (8.1, 9.2, 9.3, 10.5) I've opted to retain the use of
println! because dbg! makes it less readable. The
dbg! macro uses pretty-printing by default and this results in a simple
array such as the one in 8.1 being printed vertically instead of a
cleaner one-liner.

Co-authored-by: Eric Githinji <egithinji@google.com>
2025-02-24 14:13:43 +00:00
Eric Githinji
0daab179e9
Use dbg! instead of println! in Day 1 mng session (#2652)
As mentioned in #2478, this cleans up the code blocks when all that is
needed is a trivial debug print statement.
Only making changes to Day 1 morning session so that I can get feedback
before proceeding with the rest of the course.

---------

Co-authored-by: Eric Githinji <egithinji@google.com>
2025-02-24 14:12:56 +00:00
Eric Githinji
49e4efcd9e
Split C interop slides into smaller slides. (#2645) 2025-02-22 19:48:10 +00:00
Frances Wingerter
63cc474ba0
closures/exercise.rs: drop trait bounds from struct definition (#2649)
This is more idiomatic than what we had before.

We keep the trait bounds for the inherent impl, because the new method
can use them to guide inference of unannotated closure arguments.
2025-02-20 21:51:39 +00:00
Frances Wingerter
e16dc70903
Clarify and correct closure syntax slide (#2647)
Simplify the example, adding demonstration of return type annotation and
removing confusing "lambda" reference from speaker notes.
2025-02-20 21:50:38 +00:00
Frances Wingerter
4f8b09009a
drop: avoid confusing names (#2648)
The Droppables are already named with letters, so hopefully referencing
the nesting order of blocks instead of giving them names is clearer.
2025-02-20 20:21:32 +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
d732821edb
Fix note about undefined behavior (#2632) 2025-02-11 10:41:33 -08:00
Nicole L
d998022f75
Move use statements to beginning of widgets.rs (#2631) 2025-02-11 10:41:11 -08:00
Nicole L
f9aca3738a
Reorganize borrowck notes and add note about re-borrowing (#2635)
The speaker notes on the borrowck slide are a bit hard to read since
it's a big block of bulleted points. I've reorganized the notes to be a
bit easier to read by making some of the bullet points nested and by
moving some of the points to the "More to Explore" section. I've also
added a note on re-borrowing since students sometimes ask about it, and
I've added some playground links to demonstrate some of the points.
2025-02-07 17:05:27 -05:00
Nicole L
386757e697
Add note that borrock error can be triggered by direct mutation (#2629) 2025-02-07 11:15:00 -08:00
Nicole L
d603faca56
Add link to GridRefIter example (#2633) 2025-02-07 11:04:32 -08:00
Nicole L
c05f0b6f02
Add main method to code snippet (#2630)
The code snippet wouldn't compile/run directly because of a missing
`main` method.

Also remove unnecessary `&`.
2025-02-07 10:08:10 +01:00
Nicole L
f1459c54e1
Remove slide on shadowing (#2596) 2025-02-06 12:39:27 -08:00
Nicole L
72c7618cb4
Replace unimplemented with todo (#2594) 2025-02-06 12:35:28 -08:00
Nicole L
3229fc7c05
Fix tyop in speaker notes (#2627) 2025-02-06 11:01:19 -08:00
Nicole L
06bdb40442
Make code in expression evaluation exercise editable (#2601) 2025-02-06 11:00:46 -08:00
Nicole L
6a25d7be04
Minor whitespace changes (#2595) 2025-02-06 09:52:29 -08:00
Nicole L
e1ed6eaf47
Move struct update syntax to speaker notes (#2597) 2025-02-06 09:51:43 -08:00
Nicole L
ca137b4807
Move slide on blocks to beginning of control flow section (#2598) 2025-02-06 09:29:44 -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
Nicole L
8f01344757
Add speaker note about multiple impl blocks (#2606) 2025-02-05 16:10:55 -08:00
Nicole L
12fb4379f7
Add speaker note with manual derive example (#2607) 2025-02-05 16:10:25 -08:00
Nicole L
bb8cbbcb7c
Change values of example array in for loop slide (#2592) 2025-02-05 16:09:56 -08:00
Nicole L
cdab1a4ce5
Make nested array example editable (#2593) 2025-02-05 16:09:45 -08:00
Dustin J. Mitchell
fd7cb04a62
Improve explanation of lifetimes (#2584)
This approach seems to balance formalism with understanding. That is, it
doesn't mention contravariance, but suggests that lifetime annotations
in parameters and return values mean "opposite" things. It also
leverages the understanding that types must be specified in function
signatures, and are used to check types in the function body and at call
sites.
2025-02-05 10:58:22 -05:00
Martin Geisler
c07ac40f90
Split large unsafe function slide (#2406)
The old slice was doing several things at the same time: demonstrating
both external functions as well as unsafe Rust functions.

We now treat those two topics separately. In addition, the “Calling
Unsafe Functions” heading has become its own slide with a non-crashing
example that shows what can go wrong if an argument is misunderstood
in a call to an unsafe function. The old example didn’t actually
illustrate the danger clearly: it would produce mangled UTF-8 output,
which the Playground server refuses to print.

Part of #2445.

---------

Co-authored-by: Dustin J. Mitchell <djmitche@google.com>
Co-authored-by: Andrew Walbran <qwandor@google.com>
2025-02-05 14:00:14 +00:00
Nicole L
abf9393e60
Remove trait bound on VerbosityFilter in the generic data types slide (#2603)
It's generally more idiomatic in Rust to not have trait bounds on the
data type itself. I think we better demonstrate how trait bounds are
used in impl blocks with generic data types in the impl block below the
struct definition. I've also added a speaker note to call this out if
students ask.
2025-02-03 13:57:24 -05:00
dependabot[bot]
4218c95e8d
cargo: bump the patch group in /src/bare-metal/aps/examples with 2 updates (#2616)
Bumps the patch group in /src/bare-metal/aps/examples with 2 updates:
[log](https://github.com/rust-lang/log) and
[cc](https://github.com/rust-lang/cc-rs).

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-02-01 18:41:42 +00:00
dependabot[bot]
87d4701645
cargo: bump the patch group in /src/exercises/bare-metal/rtc with 2 updates (#2618)
Bumps the patch group in /src/exercises/bare-metal/rtc with 2 updates:
[log](https://github.com/rust-lang/log) and
[cc](https://github.com/rust-lang/cc-rs).

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-02-01 18:41:26 +00:00
dependabot[bot]
a8d8d2eaa7
cargo: bump bitflags from 2.6.0 to 2.8.0 in /src/exercises/bare-metal/rtc in the minor group (#2617)
Bumps the minor group in /src/exercises/bare-metal/rtc with 1 update:
[bitflags](https://github.com/bitflags/bitflags).

Updates `bitflags` from 2.6.0 to 2.8.0

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-02-01 18:18:38 +00:00
dependabot[bot]
0e5ee9db00
cargo: bump bitflags from 2.6.0 to 2.8.0 in /src/bare-metal/aps/examples in the minor group (#2615)
Bumps the minor group in /src/bare-metal/aps/examples with 1 update:
[bitflags](https://github.com/bitflags/bitflags).

Updates `bitflags` from 2.6.0 to 2.8.0

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-02-01 18:17:57 +00:00
dependabot[bot]
010bd291c0
cargo: bump the patch group with 8 updates (#2614)
Bumps the patch group with 8 updates:

| Package | From | To |
| --- | --- | --- |
| [clap](https://github.com/clap-rs/clap) | `4.5.23` | `4.5.27` |
| [log](https://github.com/rust-lang/log) | `0.4.22` | `0.4.25` |
| [mdbook](https://github.com/rust-lang/mdBook) | `0.4.43` | `0.4.44` |
| [serde_json](https://github.com/serde-rs/json) | `1.0.134` | `1.0.138`
|
| [fantoccini](https://github.com/jonhoo/fantoccini) | `0.21.3` |
`0.21.4` |
| [thiserror](https://github.com/dtolnay/thiserror) | `2.0.9` | `2.0.11`
|
| [cxx](https://github.com/dtolnay/cxx) | `1.0.136` | `1.0.137` |
| [cxx-build](https://github.com/dtolnay/cxx) | `1.0.136` | `1.0.137` |

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-02-01 18:17:30 +00:00
andriyDev
347de61d13
Move the "Trait Bounds" slide right after "Generic Functions". (#2589)
The "Generic Data Types" slide now uses trait bounds, which makes it
very confusing to explain. (e.g., "ignore this trait bound stuff while I
explain why we need to stutter to describe the generic args on an impl
block").

Also in the "Generic Functions" slide, the speaker notes talks about how
we essentially need to treat the generic args as black boxes - this is
probably more important to address then talking about all the ways you
can make things generic.
2025-01-30 01:34:45 +00:00
Martin Geisler
deae2e2d53
Reduce vertical space slightly in UART examples (#2407)
Co-authored-by: Dustin J. Mitchell <djmitche@google.com>
2025-01-27 13:40:48 -05:00
Dustin J. Mitchell
a846003665
Switch lifetime and variable names so they are different (#2586)
This helps clarify that the lifetime and variables names do not need to
match, but sticks to related themes (doc / document) for human clarity.

As suggested by @fw-immunant in
https://github.com/google/comprehensive-rust/pull/2585#pullrequestreview-2569184433,
which subsequently auto-merged.
2025-01-23 14:55:59 -08:00
Dustin J. Mitchell
9c03d51b74
Add a picture to Rc (#2583)
I suppose my `svgbob` skills leave a bit to be desired, but I think the
meaning is clear:


![image](https://github.com/user-attachments/assets/09fa2ebd-7364-4d23-bc97-6e7e81a9c82e)

Now that I look through the `Rc` implementation, there's a weak count
for every strong count, so the `weak: 0` here is inaccurate. But, maybe
this is too much of an implementation detail? Should I just concentrate
on strong refs? I suppose I could put a `...` in that upper-right box,
to suggest there's more going on here?
2025-01-23 09:28:20 -05:00
Dustin J. Mitchell
4ce87c5473
Improve tuple destructuring (#2582)
This slide had two code samples, neither of which had a `main` and thus
neither of which would run. This removes the first (which is redundant
to one a few slides earlier), adds a `main`, and expands the second to
use a 3-tuple.
2025-01-23 09:23:08 -05:00
Dustin J. Mitchell
b3734de08b
Include the From trait in the generic traits slide (#2570)
This saves a bunch of tabbing back and forth from the docs to the slide.
2025-01-23 09:43:43 +01:00
Dustin J. Mitchell
b3c57e4cbf
Be clear that the methods-and-traits exercise does not require generics (#2568)
When teaching the course, I got a little tripped up thinking students
would need to make the `VerbosityFilter` generic over `Logger`. Let's be
clearer that this is not required, and will be described later.

This also updates the generic-types slide to repeat the exercise,
completing that thought.
2025-01-23 09:40:59 +01:00