Serialization of multiple fields protected by tokio's RwLock

Solution 1:

Data is being changed and transferred over the network fairly often (by design), so it's probably not a good idea to wait for multiple read locks every time i need to send something.

Forget performance - this won't be your bottleneck in any sort of game networking (which does appear what you're trying to do).

The only correct way is to first acquire a read lock on each field before serializing the data, and then serialize them all. If you don't do this you end up with inconsistent states that never logically existed. A player could be alive yet have 0 hitpoints, or be disconnected yet in the game.

This can lead to deadlocks! This is the difficulty you chose when you started sharing data. There is a very good rule of thumb that can prevent deadlocks if you stick to it religiously, which you have to do throughout your code: any routine that acquires multiple locks must acquire them in the same order. If a new lock is needed but we already have other locks that come later in the order, we must first release all locks before acquiring them all again, in the correct order.

The easiest way to stick to the above is by having only a single lock for a player.