lucaspoffo/renet

Return an iterator from clients_id

Closed this issue · 4 comments

Currently RenetServer::clients_id() returns Vec but it's not very flexible and users usually wants to iterate over them in most cases. So I would suggest to return impl Iterator instead.

The problem with returning an iterator is that it would keep a reference to RenetServer, so we would not be able to call:

// This would need to be server.clients_id().collect().into_iter() {
for client_id in server.clients_id() {
   while let Some(message) = server.receive_message(client_id, channel_id) {
       // ...
   }
}

I could return an owned iterator by creating a new Vec and returning an iterator over it, but at this point, why not just return the Vec. Could also implement a new function just for the iterator I guess.

There might be a better way, not sure

Right, it won't work because of the borrow checker :(
Better keep as is then.

Could also implement a new function just for the iterator I guess.

Although, having iter_clients_id() for read-only cases would be nice.

Added in #91