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

I know that proposing Rust in this case almost became a cliché but Rust's borrowing mechanism introduces such a semantic and ensures correctness in compile time. Moreover, with RAII it can also zero the memory after object is out of scope.


Except when escape out to unsafe (as a lot of rust code does) or stop using rust because the borrow checker is brain dead:

https://github.com/rust-lang/rust/issues/6268 https://github.com/rust-lang/rust/issues/6393

Those bugs are 2 years old. And heaven forbid you have &mut self in a object.


Well, only for Box<> pointers, but yes


Ownership is for all structures on the stack. Box is little more than a rust-level wrapper around a raw pointer (well technically around a core::ptr::Unique which is the actual wrapper around a raw pointer)


Which part are you referring to with "only"? There's nothing particularly special about Box, at least, not in relation to the things the parent mentioned.


Whoops, misread "zero" as "deallocate". I meant that Box<> pointers are heap-allocated but deallocated when they go out of scope.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

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

Search: