rust-lang / book

The Rust Programming Language

Home Page:https://doc.rust-lang.org/book/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Chapter 13 closure examples tells that all the sample closures scenario are valid but in actual rust compiler reports an error.

jpmateo022 opened this issue · comments

commented

Hi,

I am currently studying rust and here in the screenshot below:

image

It says that the sample closures are all valid but when I tried it in actual. The rust compiler reports an error.

image

This closure definition syntax is valid if you call the closure so that Rust can infer the types involved. This is mentioned in this part of the text:

valid definitions that will produce the same behavior when they’re called. The
`add_one_v3` and `add_one_v4` lines require the closures to be evaluated to be
able to compile because the types will be inferred from their usage. This is

Additionally, please follow the issue template next time: if you had searched for add_one_v3, you would have found this duplicate issue that points to the text added that addresses this point explicitly.