Closed
Description
Given the following code:
numbers // Vec<i32>
.into_iter()
.filter(|x| *x % 2 == 0)
.collect::<Vec<_>>()
In VS Code, I want to select the predicate closure (|x| x % 2 == 0
), click the yellow light bulb, and choose "Extract closure into function", and the code should turn into this:
numbers // Vec<i32>
.into_iter()
.filter(predicate)
.collect::<Vec<_>>()
fn predicate(x: &i32) -> bool {
*x % 2 == 0
}
Note: The name predicate
was deduced from the signature of the filter
method. However, I wouldn't complain if rust-analyzer instead asks me for the name of the function.
Note: Currently, an option called "Extract into function" exists, but it only moves a whole expression to a new function. In regard to closure, the new function it creates is a function that returns closure, not the closure itself.