Compared to all the times I had to code review "you should be moving that shared_ptr<> in C++", I really like Rust's existing choices here. Copy
when it's trivial enough to not care, move by default so the right thing usually happens without thinking, but also really easy to .clone()
when you have to. (I needed to, essentially, .clone()
a SqlParameter
in C# the other day, and it was miserable. C#'s IClonable
totally doesn't work, and canonical C# doesn't reliably even have a "copy constructor". Hooray for #[derive(Clone)]
!) A "diffuse extra copies all over problem" adds up in cost, but is a royal pain to clean up later. And, extrapolating from shared_ptr
/unique_ptr
experience, having the copies explicit probably makes a "wait a minute, all these Arc
s can just be Box
s" realization easier.
Maybe there's a way that Copy as a concept can be extended to impl
s using Copy
types, though? Like if impl Foo<T>
automatically provided impl Foo<&T>
for trait Foo<#[in] T>
when T:Copy
? (So one Add for i32 would be enough, without needing the other three, for example.)