you can pass a unique_ptr to another function, but in so doing yours is invalidated at run-time, maintaining the single-owner invariant
Ah, hang on -- this is invalidated at *runtime*? That doesn't surprise me, but it's a crucial difference: in Rust, it is invalidated at *compile* time -- if you pass an unshared ref to a function, any attempts to reference it after that function call result in a compile error. References are more a compile-time constraint than a runtime one, so that you get fast feedback with little runtime overhead.
That's the thing about building this ownership stuff deeply and fundamentally into the language: they're able to provide *really* strong, compile-time guarantees based on it. I'm not clear whether C++ has managed to achieve that yet...
(no subject)
Date: 2017-04-21 07:27 pm (UTC)Ah, hang on -- this is invalidated at *runtime*? That doesn't surprise me, but it's a crucial difference: in Rust, it is invalidated at *compile* time -- if you pass an unshared ref to a function, any attempts to reference it after that function call result in a compile error. References are more a compile-time constraint than a runtime one, so that you get fast feedback with little runtime overhead.
That's the thing about building this ownership stuff deeply and fundamentally into the language: they're able to provide *really* strong, compile-time guarantees based on it. I'm not clear whether C++ has managed to achieve that yet...