You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
sharptrip
changed the title
Closure example does not showcase capturing
Closure example does not explain a capture
Sep 22, 2022
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
Hi,
it's just caught my eye, that closures from this example don't really explain what a capture means.
rust-by-example/src/fn/closures.md
Lines 29 to 30 in 767a6bd
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 argumenti
.Best regards,
Mikhail
The text was updated successfully, but these errors were encountered: