How to understand the sentence "However, both input and return types can be inferred and input variable names must be specified"?

I read this passage in rust-by-example/fn/closures.

The syntax and capabilities of closures make them very convenient for on the fly usage. Calling a closure is exactly like calling a function. However, both input and return types can be inferred and input variable names must be specified.

What do "input variable names must be specified" refer to? I can't figure it out.

I'm guessing they contrast this with some other languages where "magic" placeholders create implicit closures, something that you deliberately can't do in Rust. For example, one could imagine the following syntax:

let numbers = vec![1, 2, 3];
let bigger_numbers = numbers.into_iter().map(_ + 1);
                                             ^^^^^

This would cause the _ nameless placeholder to stand in for the single parameter for an automatically-created closure, of which the body is the expression noname_parameter + 1. I think this and similar features have been proposed (and rejected) before, and here the RBE guide might be trying to preemptively address such expectations.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.