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

Rust lifetimes are just the lifetimes of the memory, exactly the same as C. The only difference is you simply need to (sometimes) tell Rust where the memory for a reference comes from explicitly, where as in C you don't (but in C if you get it wrong your program will segfault, unlike Rust, or worse it might not...sometimes).


> Rust lifetimes are just the lifetimes of the memory, exactly the same as C.

Rust lifetimes are only the lifetimes of the memory that are provable by the type system. There are many valid lifetimes that are not provable. For example lifetimes that change at runtime, and self referencing lifetimes, or cyclic lifetimes. Newer versions of the borrow checker enable it to prove more lifetimes correct, but it will never be able to express all valid lifetimes of the actual memory.

This means some patterns the are completely valid cannot be expressed in safe Rust due to the limitations of the type system, but can be expressed in C.


And you can use unsafe.


Well yes, lifetimes also exist in C, but it is only in Rust that they are compiler checked




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

Search: