```
$ adb shell /data/local/tmp/hello_rust_with_dep
CANNOT LINK EXECUTABLE "/data/local/tmp/hello_rust_with_dep": library "libtextwrap.dylib.so" not found: needed by main executable
```
```
error: unsafe block missing a safety comment
--> interoperability/bindgen/main.rs:11:5
|
11 | unsafe {
| ^^^^^^^^
|
= help: consider adding a safety comment on the preceding line
= help: for further information visit https://rust-lang.github.io/rust-clippy
/master/index.html#undocumented_unsafe_blocks
= note: requested on the command line with `-D clippy::undocumented-unsafe-bl
ocks`
```
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).
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.
In https://github.com/google/comprehensive-rust/pull/1591, I changed the
implementation of the protobuf example significantly. However, I forgot
to update a comment which is referred to the old style of
implementation. I'll this slip here.
The solution to the modules exercise comes with a bunch of files. I
think it would help the students to get a quick overview of the
directory structure we've chosen first.
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(...)??`.
This is a suggestion for how we could make the protobuf exercise at the
end of day 3 better.
Generally speaking, the idea is to parse the protbuf bytes into data
types instead of only printing the parsing outcome to the console. To
make this a little more realistic, we also introduce a trait
`ProtoMessage` for message types.
I think this is more instructive than the current example. In
particular, we get to mess around with lifetimes. This might be a little
more complicated but can be a great opportunity for the students to tie
together different things they've learnt in the course so far.
What do you all think?
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.
`Ok(x?)` has the same outcome as `x` and save an unpacking/repacking
cycle.
`x as usize` has no effect when `x` already has type `usize`.
In `x < 4usize` the `usize` is unnecessary when `x` already has type
`usize`.
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>
People are often confused by this: the fact that we can remove the `*`
in the `println!()` is not because the compiler auto-derefs here (it
does not), but because `Display` is implemented for `&T where T:
Display` (a blanket implementation).
Speaker notes for Chromium's third-party crate exercise list the
transitive dependencies that will be downloaded during the exercise.
Before this commit the list was missing the `redox_syscall` crate.
Additionally, the commit sorts the crates to make it easier to compare
with the output of `git status` or `ls`.
---------
Co-authored-by: Martin Geisler <martin@geisler.net>
I don't like shortening words, so I prefer "Documentation" over "Docs".
I find this less jargony and thus easier to read (and potentially also
easier to translate).
This takes out the huge example with lots of macro magic. I don't think
we need it for an introductory course.
I also cleaned up the formatting a little and made sure to distinguish
between types and values.
---------
Co-authored-by: Dustin J. Mitchell <djmitche@google.com>
If we use a type annotation, we get around explaining the turbo fish,
which isn't trivial without having introduced generics. Type
annotations on the other hand are known already.
I swear I tested this in an actual Rust file, but I somehow messed up
when copy-pasting it into the example. The code is now in the test file
so it will be correct.
Why is the indentation wrong? Because of
https://github.com/rust-lang/mdBook/issues/1564
The indentation is not kept by the included content, which breaks the
Markdown.