Skip to content

Closures #1746

Open
Open
@junderw

Description

@junderw

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:

  1. Capturing semantics without move
  2. Capturing semantics with move (including ie. binding a reference to a variable before using it in the closure and a reference is moved)
  3. How the Fn* traits are auto-implemented.
  4. Briefly mention that async block capturing is similar to closure capturing, but that there is no 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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions