pub struct PlayerMap {
by_uuid: HashMap<Uuid, Arc<Player>>,
by_entity_id: HashMap<i32, Arc<Player>>,
order: SyncMutex<Vec<Uuid>>,
}Expand description
Thread-safe player storage with dual indexing.
Maintains two synchronized maps for O(1) lookup by either UUID or entity ID. All operations keep both maps in sync automatically.
Fields§
§by_uuid: HashMap<Uuid, Arc<Player>>Primary index by UUID (persistent identifier)
by_entity_id: HashMap<i32, Arc<Player>>Secondary index by entity ID (session-local identifier)
order: SyncMutex<Vec<Uuid>>Player UUIDs in insertion order for vanilla-visible iteration.
Implementations§
Source§impl PlayerMap
impl PlayerMap
Sourcepub fn insert(&self, player: Arc<Player>) -> bool
pub fn insert(&self, player: Arc<Player>) -> bool
Inserts a player into both maps.
Returns true if the player was inserted, false if a player with the same UUID already exists.
§Panics
Panics if another player already has the same entity ID. Entity IDs are session-unique; accepting a duplicate would break entity lookup and packet routing invariants.
Sourcepub async fn remove(&self, uuid: &Uuid) -> Option<Arc<Player>>
pub async fn remove(&self, uuid: &Uuid) -> Option<Arc<Player>>
Removes a player by UUID from both maps.
Returns the removed player if found.
Sourcepub async fn remove_player(&self, player: &Arc<Player>) -> Option<Arc<Player>>
pub async fn remove_player(&self, player: &Arc<Player>) -> Option<Arc<Player>>
Removes this exact player from both maps.
Returns the removed player if the UUID still maps to this same player handle. A stale duplicate-login cleanup must not remove the accepted player that owns the UUID.
Sourcepub fn remove_sync(&self, uuid: &Uuid) -> Option<Arc<Player>>
pub fn remove_sync(&self, uuid: &Uuid) -> Option<Arc<Player>>
Removes a player by UUID from both maps synchronously.
Returns the removed player if found. Use this when async is not available (e.g., during world changes on the tick thread).
Sourcepub fn remove_player_sync(&self, player: &Arc<Player>) -> Option<Arc<Player>>
pub fn remove_player_sync(&self, player: &Arc<Player>) -> Option<Arc<Player>>
Removes this exact player from both maps synchronously.
Sourcepub fn get_by_entity_id(&self, entity_id: i32) -> Option<Arc<Player>>
pub fn get_by_entity_id(&self, entity_id: i32) -> Option<Arc<Player>>
Gets a player by entity ID.
Sourcepub fn iter_players<F>(&self, f: F)
pub fn iter_players<F>(&self, f: F)
Iterates over all players.
The callback returns true to continue iteration, false to stop.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for PlayerMap
impl !RefUnwindSafe for PlayerMap
impl !UnwindSafe for PlayerMap
impl Send for PlayerMap
impl Sync for PlayerMap
impl Unpin for PlayerMap
impl UnsafeUnpin for PlayerMap
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreArc<SyncMutex<>>