Hey guys, i’m currently working on the following situation: https://play.rust-lang.org/?gist=7b64e70978e68c36c990c6763a14fa11&version=nightly
I talked about this earlier on #rust and understand what’s happening.
- outer_t is moved into for_loop = inner_t
- inner_t is consumed and replaced with an updated inner_t
- inner_t is dropped because scope of for loop ends
- next iteration starts and outer_t is inaccessible
I’m curious about what can be done to make this example compile with minimal changes. Can anyone help me make this work?
The main issue here is the move into for_loop which basically implies i need a Copy type, so i must wrap T first into one of the smart pointers but that’s not ideal.
No, i can not change L to take a mutable reference, because T is an object which can be consumed by Into operations… L is always guaranteed to return the exact same struct type that it consumed.
On the other hand i found this RFC which basically does what i need, but only applies to references.
There might be another feature out there which would make this example compile? So far i couldn’t find any.