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

No, from a quick glance those are only for moves of individual values. Lifetimes are something different. They are used for relating multiple (> 1) parameters / return values with each other. There is no way to have that without having a syntax for it.

It's important to note that lifetimes are not just for the compiler. They are also documentation / API contracts:

fn add_to_vec<'a>(element: &'a str, vec: &mut Vec<&'a str>) { ... }

This documents that the vec passed into the function can't outlive the element that's passed in. That's because the string (a reference (pointer) to the string data) that's passed in gets stored in the vec. So freeing the string and then using the vec would result in a use after free.

You can't have this power without a syntax for it. You could of course do some global analysis, but now you can't have API contracts like this anymore, which are important for semantic versioning.

An alternative syntax a language could use would be to have arbitrary pre- and post-conditions that the compiler can verify, which would be a whole lot more powerful, but also a lot more wordy than the short lifetime "tags" that Rust uses.



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

Search: