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

9 Commits

Author SHA1 Message Date
Nicole L
c9e08fae60
Slightly simplify binary tree exercise (#2002)
Give students a little more context for the binary tree exercise by
giving them the wrapper methods on `BinaryTree` at the start and
explicitly asking them to implement the methods on `Subtree`. I think
this simplifies the exercise a bit and makes it a bit more focused for
students.
2024-04-18 14:50:27 -04: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
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
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
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
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
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