SDL2 - Texture lifetimes

Them being part of the same struct is itself the problem -- you're trying to create a self-referencial struct. Follow the links (or start here and read forward) for some explanation on why that's problematic.

Or as another round-about explanation, the borrow checker doesn't distinguish between the stack and the heap (say), and if you had this struct...

+---------------------+
|                     |
| texture_on_stack <--+---+
|                     |   |
| texture_pointer ----+---+
|                     |
+---------------------+

...and you moved it, the pointer would dangle; therefore if you can safely achieve this data scenario with references (which you can with a method like your load_texture) the data structure must somehow be stuck in a state that can never move;[1] being borrowed forever accomplishes that.


  1. to avoid a dangling reference, which is UB ↩︎