Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Ironically, we could say that we're losing the true ownership relationships between the objects, and we're making medium-term memory leaks more likely; drop() can free a Box pointing to a child, but can't free an index. In other words, we lose the guarantee that an element is released for reuse.

AFAICT, a language would need something like higher RAII [0] or linear types [1] for that. I'd love to see Rust adopt these features too one day, though it may be difficult to do backwards compatibly.

[0] https://verdagon.dev/blog/higher-raii-7drl

[1] https://austral-lang.org/linear-types



Re linear types, Rust actually has an affine typesystem, and the compiler complains when you move a variable and try to access it, so instead you need to provide a reference if you intend to do that multiple times.

A reference is a new object that references an existing memory value. You can not store a reference unless the borrow-checker can prove that the object that stores it has a shorter lifetime than the referenced object.

That is also why you can't just pass that reference around willy-nilly, because the reference is consumed due to affine types.

I may be misunderstanding something though so feel free to correct me.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: