Why is `splice` designed as iterator?

Is there any scene to use the laziness of iter for splicing?

Do you meaning splicing two or more iterators together in sequence?
The chain method does that.

1 Like

I guess the question is about Vec::splice. And the answer is probably "give the caller more flexibility without unnecessary restricting anyone".

5 Likes

Do you mean, why is Splice an iterator? Presumably because it allows the caller to move the removed items where they want without intermediate allocation.

If you're dealing with two slices of the same length, there's swap_with_slice.

3 Likes