Use the `retain` method with a closure to keep specific elements in a `Vec` and remove the rest in place.
To retain elements in a Vec, use the retain method, which keeps only the elements that satisfy a given closure condition. This method modifies the vector in place, removing any elements for which the closure returns false.
let mut v = vec![1, 2, 3, 4, 5];
v.retain(|&x| x % 2 == 0);
// v is now [2, 4]
The retain method filters a list of items directly, keeping only the ones you want and deleting the rest. It works like a sieve that lets specific items pass through while catching and removing the others. You use it when you need to clean up a list based on a rule without creating a new list.