News for hackers. Stuff that matters.
Re:Rust via its Core Values by losvedir on Sunday April 03, 2016 @11:01PM (#11419152)
> Unfortunately, it looks like he doesn't really understand borrowing. The key idea of borrowing is that a borrowed reference can't outlive the thing it came from. It's a lifetime thing, not an immutability thing.

As a rust newbie, this touches on something I've been trying to figure out how to think about. Should I think of `&` in terms of ownership exclusively, or is it also useful to think about passing a pointer vs copying the data?

That is, suppose I have something that, semantically, I want to move into a function, and which the function later returns. I think I could also pass a `& mut` instead. I'm trying to decide how to reason about that decision. Is the compiler smart enough to turn moving/returning into passing a pointer behind the scenes? If it's a large struct do I need to think about that "optimization" of instead passing just a `&` instead of moving the whole thing?

Re:Rust via its Core Values by kibwen on Monday April 04, 2016 @03:55AM (#11420124)

  > Is the compiler smart enough to turn moving/returning 
  > into passing a pointer behind the scenes?
Rust guarantees RVO, yes, and this is even baked into its calling convention.
Re:Rust via its Core Values by rntz on Monday April 04, 2016 @03:58AM (#11420133)
> That is, suppose I have something that, semantically, I want to move into a function, and which the function later returns. I think I could also pass a `& mut` instead.

That is exactly what `&mut` is for. An &mut gives you an "ownership lease" on an object; you own it as long as you have the &mut.