4 ms·
Very cool! I don't understand the motivation about lifetimes in sync rust not being able to be arbitrary. I'm also confused because most of the time went you w
by voorwerpjes 4y ago
Very cool!
I don't understand the motivation about lifetimes in sync rust not being able to be arbitrary. I'm also confused because most of the time went you want to send data around in a async context you wrap it in `arc`, which has the pretty much analogous `rc` in a sync context which would also solve the lifetimes issue. Is there something I am missing?
- sakex 4y agoIn C++, this will compile: class T { public: T(int & m): member{m} {} int & member; } T MakeT(int m) { return T(m); } int main() { const auto t = MakeT(10); std::cout << t.member << std::endl; // UB <- member has actually been destroyed } Rust will correctly observe that the lifetime of m in `MakeT` is lower than the T object returned and will refuse to compile
- deleted 4y ago[deleted]