News for hackers. Stuff that matters.
Re:My favorite Rust function by likeliv on Sunday October 13, 2019 @12:24PM (#21241222)
That was just an example. But maybe 'x' is a BigInt type that use a memory allocation to store its contents. The ownership would be transferred to the return value
Re:My favorite Rust function by dorfsmay on Sunday October 13, 2019 @02:17PM (#21241867)
But again, what would be the drawback(s) of using a pointer instead of transfering the ownership?

Not rethorical, I'm genuinely curious as I used to struggle with the copy vs move decisions, and a bunch of issues with ownership which went all away when I started using pointer/borrowing everywhere.

Re:My favorite Rust function by Dylan16807 on Thursday October 17, 2019 @12:39AM (#21278966)
The downside to using a mutable reference instead of passing around ownership is just that it would be awkward.

You'd have to write two extra lines of code to set up y and z separately from calling add(), and you'd have to make them mutable which is an extra mental burden.

And an immutable reference is bad because it would force extra objects to be allocated, wasting time and cache space.