Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ex31 1 tempfile #1288

Closed
wants to merge 3 commits into from
Closed

Ex31 1 tempfile #1288

wants to merge 3 commits into from

Conversation

njr0
Copy link
Contributor

@njr0 njr0 commented Oct 2, 2023

Add missing use in model solution

Fixes #1287.

njr0 added 3 commits October 2, 2023 14:34
Exercise 31.1 needs

use tempfile::tempfile;

to work, and also for `tempfile = "3"` to be added to Cargo.toml.
@google-cla
Copy link

google-cla bot commented Oct 2, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@mgeisler
Copy link
Collaborator

mgeisler commented Oct 2, 2023

Thanks! However, as explained in #1286 (comment), this should not be necessary.

I triggered the test run, but as expected it fails:

error[E0432]: unresolved import `tempfile`
  --> src/exercises/day-3/safe-ffi-wrapper.rs:18:5
   |
18 | use tempfile::tempfile;   // requires tempfile = "3" in Cargo.toml dependencies
   |     ^^^^^^^^ use of undeclared crate or module `tempfile`

For more information about this error, try `rustc --explain E0432`.
error: could not compile `comprehensive-rust` (bin "safe-ffi-wrapper") due to previous error
warning: build failed, waiting for other jobs to finish...
Error: Process completed with exit code 101.

@njr0
Copy link
Contributor Author

njr0 commented Oct 2, 2023

I'm sure you're right, but I don't understand.

If I do cargo new ex31_1, replace the main with your model solution and run it, it doesn't work for me because it doesn't know about the tempfile. (It's slightly strange, but at the start of the course you say you want to encourage students to use cargo to solve the exercises, but in most of them you recommend going to a playground instead. I have always used cargo to do the exercises.)

@mgeisler
Copy link
Collaborator

mgeisler commented Oct 2, 2023

I'm sure you're right, but I don't understand.

If I do cargo new ex31_1, replace the main with your model solution and run it, it doesn't work for me because it doesn't know about the tempfile.

That is correct! My thinking was that people would copy the code from the exercise page and then expand that to solve the exercise.

The unit tests found in the solution are actually there for my own safety: they allow me to ensure that the solution works.

I see now that this is rather confusing! We've never explained anywhere that the solutions have dependencies outside of the standard library.

(It's slightly strange, but at the start of the course you say you want to encourage students to use cargo to solve the exercises, but in most of them you recommend going to a playground instead. I have always used cargo to do the exercises.)

Yeah, that's also a good point! Originally, I wrote the entire course centered around the Rust Playground — mostly because I was unsure about how complicated it would be to have 20 course participants install and set up Rust on Linux and Mac laptops... I wanted to avoid having to deal with random problems of that setup. However, it is of course an unnatural way to write larger amounts of Rust code, so I later added the recommendation to install Rust locally. It seems to work okay in the classes we teach as well: people normally set this up ahead of time.

So in short, we should update the boiler plate text for how the exercises are done. I created #1289 for this.

@mgeisler
Copy link
Collaborator

mgeisler commented Oct 2, 2023

#1290 is about expanding the solutions to mention their dependencies.

@mgeisler
Copy link
Collaborator

mgeisler commented Oct 2, 2023

Thanks for the PR. I'll close this now since the real problem is a matter of documentation.

@mgeisler mgeisler closed this Oct 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exercise 31.1: Safe FFI Wrapper
2 participants