Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return an iterator from clients_id #47

Closed
Shatur opened this issue Sep 20, 2022 · 4 comments
Closed

Return an iterator from clients_id #47

Shatur opened this issue Sep 20, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@Shatur
Copy link
Contributor

Shatur commented Sep 20, 2022

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.

@lucaspoffo lucaspoffo added the enhancement New feature or request label Oct 1, 2022
@lucaspoffo lucaspoffo changed the title Return an iterator fron clients_id Return an iterator from clients_id Oct 22, 2022
@lucaspoffo
Copy link
Owner

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

@Shatur
Copy link
Contributor Author

Shatur commented Oct 22, 2022

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

@Shatur Shatur closed this as completed Oct 22, 2022
@Shatur
Copy link
Contributor Author

Shatur commented Oct 22, 2022

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

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

@Shatur Shatur reopened this Oct 22, 2022
@lucaspoffo
Copy link
Owner

Added in #91

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants