News for hackers. Stuff that matters.
Re:What Rust Can Do That Other Languages Can't by willvarfar on Monday February 06, 2017 @04:30AM (#13577926)
The article is not about returning a reference to a struct member, its about returning a reference to something on the stack rather than heap.
Re:What Rust Can Do That Other Languages Can't by topspin on Monday February 06, 2017 @04:56AM (#13578056)
Rust ownership applies to heap allocated objects as well; if you return a reference to a member of a heap allocated struct that reference cannot outlive the struct allocation. The point of the article is more general than "stack vs heap;" other languages are either incapable of expressing a reference to a member of a heap allocated struct or incapable of ensuring the memory safety of such a reference.
Re:What Rust Can Do That Other Languages Can't by willvarfar on Monday February 06, 2017 @05:02AM (#13578081)
As the article notes, garbage-collected languages can ensure the memory safety of a pointer into a heap object.
Re:What Rust Can Do That Other Languages Can't by TuringTest on Monday February 06, 2017 @07:06AM (#13578684)
But not at compile time, which is what Rust provides.
Re:What Rust Can Do That Other Languages Can't by imron on Monday February 06, 2017 @04:37AM (#13577950)
And crucially, enforcing that no references to the returned member will outlive the containing struct.