Ownership &mut Vec<Foo>

  1. I have this code:
pub struct Foo {}

pub fn good(dst: &mut Vec<Foo>, src: &mut Vec<Foo>) {
    while src.len() != 0 {

pub fn bad(dst: &mut Vec<Foo>, src: &mut Vec<Foo>) {
    for x in src.into_iter().rev() {

  1. I would like to write the same function via iterator instead of pop.

  2. How can I do this? The requirements are:

3a. src ends up empty
3b. elements of src are reversed + appended to dst


Actually, using iterators, it looks pretty nice!

Note that this still uses a copy, which forces your type to be copy
Look at @cuviper’s post below