book icon indicating copy to clipboard operation
book copied to clipboard

Chapter 13-1 Contradictory statements in `Capturing the Environment with Closures` section.

Open asher-gh opened this issue 3 years ago • 0 comments

  • [x] I have checked the latest main branch to see if this has already been fixed
  • [x] I have searched existing issues and pull requests for duplicates

URL to the section(s) of the book with this problem: https://doc.rust-lang.org/book/ch13-01-closures.html#capturing-the-environment-with-closures

Description of the problem: When defining the memory overhead in using closure, if the closure doesn't use any value from its environment, then there should not be any overhead.

When a closure captures a value from its environment, it uses memory to store the values for use in the closure body. This use of memory is overhead that we don’t want to pay in more common cases where we want to execute code that doesn’t capture its environment. Because functions are never allowed to capture their environment, defining and using functions will never incur this overhead.

Then reasoning for not using closures where we don't capture value gets redundant

asher-gh avatar Nov 29 '21 15:11 asher-gh