News for hackers. Stuff that matters.
Re:Should Small Rust Structs be Passed by-copy or by-borrow? by Rustwerks on Saturday December 31, 2022 @09:51AM (#34196903)
I just went through all of this when building a raytracer.

* Sprinkling & around everything in math expressions does make them ugly. Maybe rust needs an asBorrow or similar?

* If you inline everything then the speed is the same.

* Link time optimizations are also an easy win.

https://github.com/mcallahan/lightray

Re:Should Small Rust Structs be Passed by-copy or by-borrow? by masklinn on Saturday December 31, 2022 @09:58AM (#34196978)
> * Sprinkling & around everything in math expressions does make them ugly. Maybe rust needs an asBorrow or similar?

Do you mean AsRef, or do you mean magic which automatically borrows parameters and is specifically what rust does not do any more than e.g. C does?

Though you can probably get both if the by-ref version is faster (or more convenient internally): wrap the by-ref function with a by-value wrapper which is #[inline]-ed, this way the interface is by value but the actual parameter passing is byref (as the value-consuming wrapper will be inlined and essentially removed).

Re:Should Small Rust Structs be Passed by-copy or by-borrow? by woodruffw on Saturday December 31, 2022 @02:52PM (#34200060)
> Maybe rust needs an asBorrow or similar?

FWIW, the `Borrow`, `AsRef`, and `Deref` traits all exist to support different variants of this.