DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

77fd1fd8a7607f913111a95f5e57f95ab440375b — Jonni Liljamo 1 year, 7 months ago a713ed5
feat(client): finish redo player borrows
1 files changed, 10 insertions(+), 5 deletions(-)

M client/src/game_status/parser.rs
M client/src/game_status/parser.rs => client/src/game_status/parser.rs +10 -5
@@ 19,17 19,22 @@ fn get_invoker_target<'a, K, V>(
    players: &'a mut HashMap<K, V>,
    invoker: &K,
    target: &K
) -> (&'a mut V, Option<&'a mut V>)
) -> (&'a mut V, &'a mut V)
where
    K: Eq + std::hash::Hash,
{
    if invoker == target {
        return (players.get_mut(invoker).unwrap(), None);
    }
    unsafe {
        // NOTE: soo... I don't really know the consequences of possibly
        // having two mutable references to the same value, but I guess
        // I'll find out!
        // in many instances where people wanted multiple mutable references
        // to Vec or HashMap values, they only gave one in wrappers like this,
        // if the wanted values were the same.
        // e.g. returning (V, None), if the keys were the same.

        let invoker_ref = players.get_mut(invoker).unwrap() as *mut _;
        let target_ref = players.get_mut(target).unwrap() as *mut _;
        (&mut *invoker_ref, Some(&mut *target_ref))
        (&mut *invoker_ref, &mut *target_ref)
    }
}