I have a Vec
containing character data.
let characters: Vec<CharacterState>
I want to run the character AI concurrently on each character. This is not for performance reasons, but because each AI has cooldown periods in which it sleeps, allowing other AIs to run.
The AI is allowed to mutate the CharacterState
, but only the one it was assigned to. Therefore theoretically each AI accesses a separate part of the Vec
, and there would not be multiple references to any CharacterState
.
I am struggling to express this in rust however. How do I:
- Split the
Vec
into multiple mutable references, one for each item. - Spawn a task for each item.
- Await all the resulting tasks.