closure
closure copied to clipboard
New capture syntax with better IDE support
Hi,
currently the body of the closure is captured by $($tail:tt)*, i.e. as tokens. This doesn't play well with IDE (e.g. rust-analyzer).
If we capture the body as $expr or $block then IDE knows all types and able to autocomplete.
It is possible to parse captures list with the $tt rule and avoid conflict with the rest of the macro if it is enclosed in the delimiters ([], () or {}).
So the new syntax will be
closure!([ref a, ref mut b] |x| {
*b += 10;
x + a
})
You can see that it works here

I can make a PR for it, but we need to decide how to introduce this breaking change. As a fork, as a new major version, as a new macro with alternative name?