closure icon indicating copy to clipboard operation
closure copied to clipboard

New capture syntax with better IDE support

Open technic opened this issue 4 years ago • 0 comments

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 image

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?

technic avatar Aug 19 '21 13:08 technic