News for hackers. Stuff that matters.
Re:Should Small Rust Structs be Passed by-copy or by-borrow? by lukaszwojtow on Saturday December 31, 2022 @12:01PM (#34198313)
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.
Re:Should Small Rust Structs be Passed by-copy or by-borrow? by carlmr on Saturday December 31, 2022 @12:05PM (#34198349)
Exactly, 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.

Re:Should Small Rust Structs be Passed by-copy or by-borrow? by QuadDamaged on Saturday December 31, 2022 @01:10PM (#34199001)
Exactly 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.
Re:Should Small Rust Structs be Passed by-copy or by-borrow? by theptip on Saturday December 31, 2022 @01:41PM (#34199339)
Rust noob here - is it common to see a struct lose Copy as things grow?
Re:Should Small Rust Structs be Passed by-copy or by-borrow? by zozbot234 on Saturday December 31, 2022 @01:51PM (#34199446)
If 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.
Re:Should Small Rust Structs be Passed by-copy or by-borrow? by eterevsky on Saturday December 31, 2022 @03:00PM (#34200141)
If it's a 3D real-valued vector, or similarly basic structure, you can be fairly certain, that it will stay copyable.
Re:Should Small Rust Structs be Passed by-copy or by-borrow? by josephg on Saturday December 31, 2022 @03:48PM (#34200586)
I agree. Being copyable is part of the signature for something like this. Explicitly so in rust.
Re:Should Small Rust Structs be Passed by-copy or by-borrow? by sedatk on Saturday December 31, 2022 @07:02PM (#34202075)
> 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.