From 77fd1fd8a7607f913111a95f5e57f95ab440375b Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Sun, 7 May 2023 14:42:00 +0300 Subject: [PATCH] feat(client): finish redo player borrows --- client/src/game_status/parser.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/client/src/game_status/parser.rs b/client/src/game_status/parser.rs index 8c2011d..1203eaf 100644 --- a/client/src/game_status/parser.rs +++ b/client/src/game_status/parser.rs @@ -19,17 +19,22 @@ fn get_invoker_target<'a, K, V>( players: &'a mut HashMap, 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) } } -- 2.44.1