Lifetime when moving ownership to thread

The closure is only 'static if everything it captures is 'static. Using move is a good start, but the values you captured with move still have to be 'static too. You have rx: Receiver<M>, which can only be 'static if the type M is too. You can add this bound where M: ToMessage + 'static.

If this were not enforced, then it would be possible to smuggle a borrowed M value to the 'static thread, where its lifetime would not be properly respected.

3 Likes