From 747699cbdc88e7d5f1c66e76d27f68253450d25f Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Tue, 4 Jun 2024 18:45:34 +0100 Subject: [PATCH] make next_client_id a lambda This is neater at the call site and makes it clear that this is only ever supposed to be an incremental ID and nothing else. As suggested by max (pr2502) in https://github.com/pr2502/ra-multiplex/pull/66#discussion_r1626394771 --- src/server.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/server.rs b/src/server.rs index 5eb9c75..8e22176 100644 --- a/src/server.rs +++ b/src/server.rs @@ -12,12 +12,13 @@ use crate::socketwrapper::Listener; pub async fn run(config: &Config) -> Result<()> { let instance_map = InstanceMap::new(config).await; let next_client_id = AtomicUsize::new(0); + let next_client_id = || next_client_id.fetch_add(1, Ordering::Relaxed); let listener = Listener::bind(&config.listen).await.context("listen")?; loop { match listener.accept().await { Ok((socket, _addr)) => { - let client_id = next_client_id.fetch_add(1, Ordering::Relaxed); + let client_id = next_client_id(); let instance_map = instance_map.clone(); task::spawn(