-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
Closures #1746
Comments
@divyaranjan1905 also suggested to add a set of exercises about closures in #2096. Capturing is one part of closures. So you are welcome to join forces and create a PR :D I won't include async in these exercises since Rustlings doesn't teach async yet. I am waiting for the new async chapter to be included in the official Rust book to create a set of async exercises then. See #2040 Keep in mind that I won't merge the PR until I want to publish version 7. So I can review it now and automatically merge it later before the next major release. |
Fn*
traits?
I think there’s an open PR that adds a bit of closures to the functions lesson. I feel like that is a good idea to get the student at least a little bit used to closures before going into more depth. I think closures should be explained after traits and tests. This is in line with the Rust book as well. |
Indeed, as I proposed in the issue, it would replace the currently 18th set (iterators), so would be after traits and tests. |
Yep, @mo8it I think that'll be in line with the chapter from The Book. I'm considering to keep the number of exercises to 4, or at most 5. |
I was actually thinking of going a bit more in-depth with closures. Not too deep, but deep enough to give people a good overview of capturing, the Fn traits and how they're implemented automatically, and other things. Since Closures are a pretty important part of many aspects of Rust, I think it warrants its own folder. I have created a sample exercise to get started. If you have a timeline for v7 I can try to find some time before then. Thanks. |
Actually @divyaranjan1905, @junderw , when I wrote that couple of exercises last year (#1748), I considered them a gentle introduction to closures. I still think it's a good idea to have a taste of closures early in those chapters (functions and move_semantics), and definitely a very good thing to add a dedicated chapter later to build a deeper understanding (probably between traits and iterators). @mo8it, I updated the PR #1748 to compile to the new rustlings standard, if you think it's valuable to merge. |
I rebased and added a closures2.rs to the PR in #2099 |
One topic I see new people hit pretty early on is the capturing semantics and the
Fn*
traits.I was thinking of adding a few lessons to show:
move
move
(including ie. binding a reference to a variable before using it in the closure and a reference is moved)Fn*
traits are auto-implemented.Fn*
traits for async-block-futures.I wanted to read the room a bit before actually putting time into this. Do we think this might be a bit too advanced for rustlings? Would it depend on the actual content? Would anyone be willing to help review my lessons to try and get it over the finish line?
It's an issue I get asked about constantly, especially when dealing with GUI frameworks like egui that make use of lots of nested closures... it might help people intuit these issues more clearly.
Let me know what you think!
The text was updated successfully, but these errors were encountered: