Suppose I have a Vec and I want to replace it with the contents of an iterator:
let mut v = vec![0, 1, 2, 3];
v = (0..4).map(|x| x * x).collect();
If the original Vec already had enough capacity allocated, will it reuse its memory, or does the buffer containing [0, 1, 2, 3] get freed and a new buffer allocated for the result of Iterator::collect()?