From 5818c0f51618a3c7568570788a0b5858604d9e21 Mon Sep 17 00:00:00 2001 From: Nikita Vilunov Date: Wed, 6 Sep 2023 18:03:12 +0200 Subject: [PATCH] de-arcify PlayerRegistry --- src/core/player.rs | 14 +++++++------- src/main.rs | 2 +- src/projections/irc/mod.rs | 6 +++--- src/projections/xmpp/mod.rs | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/core/player.rs b/src/core/player.rs index 0a2a8b7..b3027f2 100644 --- a/src/core/player.rs +++ b/src/core/player.rs @@ -227,12 +227,12 @@ pub enum Updates { } /// Handle to a player registry — a shared data structure containing information about players. -pub struct PlayerRegistry(RwLock); -impl PlayerRegistry { +pub struct PlayerRegistry<'a>(RwLock>); +impl<'a> PlayerRegistry<'a> { pub fn empty( - room_registry: RoomRegistry, - metrics: &mut MetricsRegistry, - ) -> Result { + room_registry: &'a RoomRegistry, + metrics: &MetricsRegistry, + ) -> Result> { let metric_active_players = IntGauge::new("chat_players_active", "Number of alive player actors")?; metrics.register(Box::new(metric_active_players.clone()))?; @@ -276,8 +276,8 @@ impl PlayerRegistry { } /// The player registry state representation. -struct PlayerRegistryInner { - room_registry: RoomRegistry, +struct PlayerRegistryInner<'a> { + room_registry: &'a RoomRegistry, players: HashMap)>, metric_active_players: IntGauge, } diff --git a/src/main.rs b/src/main.rs index 6b081ad..211e62f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -54,7 +54,7 @@ async fn main() -> Result<()> { let mut metrics = MetricsRegistry::new(); let storage = Storage::open(storage_config).await?; let rooms = RoomRegistry::new(&mut metrics, storage.clone())?; - let mut players = PlayerRegistry::empty(rooms.clone(), &mut metrics)?; + let mut players = PlayerRegistry::empty(&rooms, &metrics)?; // unsafe: outer future is never dropped, scope is joined on `scope.collect` let mut scope = unsafe { Scope::create() }; diff --git a/src/projections/irc/mod.rs b/src/projections/irc/mod.rs index 13477f9..7a6fe97 100644 --- a/src/projections/irc/mod.rs +++ b/src/projections/irc/mod.rs @@ -42,7 +42,7 @@ async fn handle_socket( config: ServerConfig, mut stream: TcpStream, socket_addr: &SocketAddr, - players: &PlayerRegistry, + players: &PlayerRegistry<'_>, rooms: &RoomRegistry, termination: Deferred<()>, // TODO use it to stop the connection gracefully storage: &Storage, @@ -175,7 +175,7 @@ async fn handle_registration<'a>( async fn handle_registered_socket<'a>( config: ServerConfig, - players: &PlayerRegistry, + players: &PlayerRegistry<'_>, rooms: &RoomRegistry, reader: &mut BufReader>, writer: &mut BufWriter>, @@ -690,7 +690,7 @@ async fn produce_on_join_cmd_messages( pub async fn launch<'a>( config: &'a ServerConfig, - players: &'a PlayerRegistry, + players: &'a PlayerRegistry<'_>, rooms: &'a RoomRegistry, metrics: &'a MetricsRegistry, storage: &'a Storage, diff --git a/src/projections/xmpp/mod.rs b/src/projections/xmpp/mod.rs index 5382a88..ac592fd 100644 --- a/src/projections/xmpp/mod.rs +++ b/src/projections/xmpp/mod.rs @@ -54,7 +54,7 @@ struct Authenticated { pub async fn launch<'a>( config: ServerConfig, - players: &'a PlayerRegistry, + players: &'a PlayerRegistry<'_>, rooms: &'a RoomRegistry, metrics: &'a MetricsRegistry, scope: &mut Scope<'a>, @@ -139,7 +139,7 @@ async fn handle_socket( config: Arc, mut stream: TcpStream, socket_addr: &SocketAddr, - players: &PlayerRegistry, + players: &PlayerRegistry<'_>, rooms: &RoomRegistry, termination: Deferred<()>, // TODO use it to stop the connection gracefully ) -> Result<()> {