4 ms·
I've allocated both these things on the heap and Rust simply won't let me store them both together. I don't know about you but this is an extremely common patte
by typon 5y ago
I've allocated both these things on the heap and Rust simply won't let me store them both together. I don't know about you but this is an extremely common pattern in almost all languages, you just don't think about it in the gc languages and in C++ storing pointers is no issue. The popularity of crates like rental also shows that it's not as easily avoidable as you suggest.
- jjnoakes 5y agoCan you post a simple code example? It is hard to imagine what the difficulty is.
- typon 5y agoYou can read through this SO question and the top response does a good job explaining the possible solutions: https://stackoverflow.com/questions/32300132/why-cant-i-store-a-value-and-a-reference-to-that-value-in-the-same-struct https://stackoverflow.com/questions/32300132/why-cant-i-stor...
- jjnoakes 5y agoSeems like using Box solves this issue fairly simply.