Skip to content

Guide chapter on Closures is inconsistent and incomplete #20667

Closed
@jsgf

Description

@jsgf

The Guide's discussion of Closures has several problems:

It doesn't explain the |&:| syntax at all. The examples have been updated to use it, but the prose still just talks about "||". I think this is the right place to clarify what |:|, |&:| and |&mut:| mean, and perhaps how they relate to the Fn traits (which I don't really understand, which I was looking here for clarification).

The example using "twice()" uses two different syntaxes. First it says:

 fn twice<F: Fn(i32) -> i32>(x: i32, f: F) -> i32 {

but later it says

fn twice(x: i32, f: |i32| -> i32) -> i32 {

Are these equivalent?

I understand this is still in flux, and I gather the |:| syntax is going to go away (?) or become mostly optional(?) - either way, a paragraph with a bit of explanation would be useful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions