3 ms·
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 str
by topspin 10y ago
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.
- willvarfar 10y agoAs the article notes, garbage-collected languages can ensure the memory safety of a pointer into a heap object.
- TuringTest 10y agoBut not at compile time, which is what Rust provides.