Clone Vector in rust except at one index
In my opinion none of your solution is idiomatic and all use an useless comparaison.

Using for loop:


Doesn't pre-allocate the vector
Use a comparaison that could be avoid


Using functional style:


Use a comparaison that could be avoid


Using mem replace:


Use a comparaison that could be avoid
Is unnecessary complex to just copy a vector


Also, you should avoid take a &amp;Vec&lt;T&gt; as parameter, it's much better to take a &amp;[T]. See: Why is it discouraged to accept a reference to a String (&amp;String), Vec (&amp;Vec), or Box (&amp;Box) as a function argument?

I would use one of the following version:

#[derive(Clone)]
struct Pokemon {
}

fn a(pokemons: &amp;[Pokemon], i: usize, pokemon: Pokemon) -&gt; Vec&lt;Pokemon&gt; {
    let mut digimons = Vec::with_capacity(pokemons.len());

    digimons.extend_from_slice(&amp;pokemons[0..i]);
    digimons.push(pokemon);
    digimons.extend_from_slice(&amp;pokemons[i + 1..]);

    digimons
}

fn b(pokemons: &amp;[Pokemon], i: usize, pokemon: Pokemon) -&gt; Vec&lt;Pokemon&gt; {
    let mut digimons = pokemons.to_vec();
    digimons[i] = pokemon;

    digimons
}

fn c(pokemons: &amp;[Pokemon], i: usize, pokemon: Pokemon) -&gt; Vec&lt;Pokemon&gt; {
    pokemons[0..i]
        .iter()
        .cloned()
        .chain(std::iter::once(pokemon))
        .chain(pokemons[i + 1..].iter().cloned())
        .collect()
}


I don't really know witch version is better, a() and c() should be the same but sometime chain() is not optimized away. And b() is probably the most straightforward solution. I think I would choice a() in a production code.

However, looking at the assembly, we can see that a() and c() doesn't produce the same, and that b() is the simplest.