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

Confusing closure example #1611

Open
sharptrip opened this issue Sep 22, 2022 · 0 comments
Open

Confusing closure example #1611

sharptrip opened this issue Sep 22, 2022 · 0 comments

Comments

@sharptrip
Copy link

sharptrip commented Sep 22, 2022

Hi,

it's just caught my eye, that closures from this example don't really explain what a capture means.

let closure_annotated = |i: i32| -> i32 { i + 1 };
let closure_inferred = |i | i + 1 ;

As a totally new to rust I've got an impression that closures in rust capture the whole outer scope disregards of where the closure is defined in code, e.g., before or after the captured variable.

Upd. and then I realised that, probably, this example should never be read as "an example of capturing". What confused me is the beginning explaining what a closure is, giving its probably the most important characteristic first.

Still I would add a capture example here, otherwise it seems just like another way of defining a function (which is probably true as well), with even more confusing variable i having the same name as a function/closure argument i.

Best regards,
Mikhail

@sharptrip sharptrip changed the title Closure example does not showcase capturing Closure example does not explain a capture Sep 22, 2022
@sharptrip sharptrip changed the title Closure example does not explain a capture Confusing closure example Sep 22, 2022
jon32446 added a commit to jon32446/rust-by-example that referenced this issue Nov 11, 2022
marioidival added a commit that referenced this issue Nov 11, 2022
Clarify the confusing closure example #1611
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

No branches or pull requests

1 participant