pub struct PlayerRegistry<Player: PlayerInfo> { /* private fields */ }Expand description
A registry for managing players by both their UUID and NFC UID.
The registry ensures that updates to players’ NFC UIDs automatically keep internal lookup maps in sync.
Implementations§
Source§impl<Player: PlayerInfo> PlayerRegistry<Player>
impl<Player: PlayerInfo> PlayerRegistry<Player>
Sourcepub fn new(players: Vec<Player>) -> Self
pub fn new(players: Vec<Player>) -> Self
Creates a new PlayerRegistry from a list of players
Sourcepub fn get_by_id(&self, id: Uuid) -> Option<Arc<RwLock<Player>>>
pub fn get_by_id(&self, id: Uuid) -> Option<Arc<RwLock<Player>>>
Returns the shared player reference (Arc) by their UUID.
Use Self::read_by_id() if you only need read access.
Sourcepub fn get_by_nfc_uid(&self, nfc_uid: NfcUid) -> Option<Arc<RwLock<Player>>>
pub fn get_by_nfc_uid(&self, nfc_uid: NfcUid) -> Option<Arc<RwLock<Player>>>
Returns the shared player reference (Arc) by their NFC UID.
/// Use Self::read_by_nfc_uid() if you only need read access.
Sourcepub fn read_by_id(&self, id: Uuid) -> Option<RwLockReadGuard<'_, Player>>
pub fn read_by_id(&self, id: Uuid) -> Option<RwLockReadGuard<'_, Player>>
Returns a read-only lock on a player by their UUID.
Returns None if no player with the given ID exists.
Sourcepub fn read_by_nfc_uid(
&self,
nfc_uid: NfcUid,
) -> Option<RwLockReadGuard<'_, Player>>
pub fn read_by_nfc_uid( &self, nfc_uid: NfcUid, ) -> Option<RwLockReadGuard<'_, Player>>
Returns a read-only lock on a player by their NFC UID.
Returns None if no player with the given NFC UID exists.
Sourcepub fn contains_id(&self, id: Uuid) -> bool
pub fn contains_id(&self, id: Uuid) -> bool
Returns true if a player with the given UUID exists in the registry.
Sourcepub fn mutate_by_id<F>(&mut self, id: Uuid, mutator: F)where
F: FnOnce(&mut Player),
pub fn mutate_by_id<F>(&mut self, id: Uuid, mutator: F)where
F: FnOnce(&mut Player),
Mutates a player by their UUID.
Automatically updates the internal NFC UID lookup map if the player’s NFC UID changes.
If no player with the given ID exists, this method does nothing.