Skip to content

Commit

Permalink
simplify enumerate
Browse files Browse the repository at this point in the history
  • Loading branch information
feschber committed Dec 15, 2023
1 parent 5fc02d4 commit 48f7ad3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
5 changes: 4 additions & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 48f7ad3

Please sign in to comment.