5 ms·
I always prefer by-borrow. That's because in the future this struct may become non-copy and that means some unnecessary refactoring. My thinking is a bit like "
by lukaszwojtow 4y ago
I always prefer by-borrow. That's because in the future this struct may become non-copy and that means some unnecessary refactoring.
My thinking is a bit like "don't take ownership if not needed" - the "not needed" part is the most important thing. Don't require things that are not needed.
- carlmr 4y agoExactly, and if performance at some point matters: benchmark! And I would bet 9 times out of 10 it won't be the bottleneck or even make a measurable difference.
- QuadDamaged 4y agoExactly why IMHO the rust stdlib is so easy to understand. Ownership only when required as a design principle tends to make the design of the overall system more consistent / easier to approach.
- theptip 4y agoRust noob here - is it common to see a struct lose Copy as things grow?
- zozbot234 4y agoIf a struct might lose Copy you shouldn't implement Copy at all, to preserve forward compatibility. You can still derive Clone in most cases; using .clone() does not per se add any overhead.
- eterevsky 4y agoIf it's a 3D real-valued vector, or similarly basic structure, you can be fairly certain, that it will stay copyable.
- josephg 4y agoI agree. Being copyable is part of the signature for something like this. Explicitly so in rust.
- sedatk 4y ago> don't take ownership if not needed That's my approach too as a Rust newbie. Borrow by default and take ownership only when needed, for the best ergononmics.