The .push()
method on Vec<T>
takes as its argument a &mut Vec<T>
, and the addition of the new element is a side effect.
What is the reason it was decided against push
to be purely functional such that its API would look this:
fn push(mut self, elem) -> Self
Would taking ownership of the Vec<T>
not be ergonomic in some way? I do not believe there to be a substantial performance hit by moving it, given that Vec
is just a fat pointer.