3 ms·
> My answer to by-copy versus by-borrow for small Rust structs is by-copy The author is making the case for special treatment of structs for a special case. F
by fnord77 7y ago
> My answer to by-copy versus by-borrow for small Rust structs is by-copy
The author is making the case for special treatment of structs for a special case. For a performance gain that's probably below the margin of error. This is negating the elegance and consistency of rust for a special case. I think the author thinks too much in C++ terms and is sort of missing the point of Rust (or at least one point of rust).
- gopalv 7y ago> The author is making the case for special treatment of structs for a special case. The struct by-copy is mostly a good API thing in a lot of scenarios, particularly when the objects are <1 cache line. Even more so, when you're only writing half the code and want to separate the actions within a function from any side-effects outside. I would say that the performance difference for small structures is irrelevant to the extra hop, particularly if the copied location is the stack on the callee.
- fnord77 7y ago> Even more so, when you're only writing half the code and want to separate the actions within a function from any side-effects outside. Due to the default immutability of references and the fact the compiler won't allow you to won't allow you to share data between threads (without jumping through a lot of hoops), the risk of side-effects are pretty well neutralized. Another selling point of Rust.