simplify enumerate

This commit is contained in:
Ferdinand Schober
2023-12-15 20:47:51 +01:00
parent 5fc02d471b
commit 48f7ad3592
2 changed files with 10 additions and 7 deletions

View File

@@ -189,11 +189,11 @@ impl ClientManager {
self.clients.get_mut(client as usize)?.as_mut()
}
pub fn enumerate(&self) -> Vec<(Client, bool)> {
self.clients
.iter()
.filter_map(|s| s.as_ref())
.map(|s| (s.client.clone(), s.active))
.collect()
pub fn get_client_states(&self) -> impl Iterator<Item = &ClientState> {
self.clients.iter().filter_map(|x| x.as_ref())
}
pub fn get_client_states_mut(&mut self) -> impl Iterator<Item = &mut ClientState> {
self.clients.iter_mut().filter_map(|x| x.as_mut())
}
}

View File

@@ -502,7 +502,10 @@ impl Server {
}
async fn enumerate(&mut self) {
let clients = self.client_manager.enumerate();
let clients = self.client_manager
.get_client_states()
.map(|s| (s.client.clone(), s.active))
.collect();
if let Err(e) = self
.frontend
.notify_all(FrontendNotify::Enumerate(clients))