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

Implement Index<usize> for Events #681

Closed
dtolnay opened this Issue Aug 19, 2017 · 4 comments

Comments

Projects
None yet
4 participants
@dtolnay
Copy link

dtolnay commented Aug 19, 2017

The mio::Events type looks a lot like Vec - it has a function get(usize) -> Option<Event> which returns None if the index is out of bounds, and it has IntoIterator. It would be convenient to implement Index to enable square-bracket indexing that panics on out of bounds.

println!("{:?}", events[0]);
@ahmedcharles

This comment has been minimized.

Copy link
Collaborator

ahmedcharles commented Aug 20, 2017

This isn't trivial. The epoll implementation of Events doesn't store Event instances directly, it stores libc::epoll-event instances. This is why get(usize) returns Option<Event> rather than Option<&Event>. Index requires &Event, which can't be a temporary, because it doesn't live long enough.

@alexcrichton

This comment has been minimized.

Copy link
Contributor

alexcrichton commented Aug 20, 2017

Ah yes this isn't implementable easily and intentionally so, we often perform translations on the returned events from the system to coalesce and/or generate more mio events.

@dtolnay dtolnay closed this Aug 20, 2017

@carllerche

This comment has been minimized.

Copy link
Owner

carllerche commented Aug 21, 2017

Actually I'm pretty sure we wanted to deprecate indexed access in favor of an iterator only API.

@dtolnay

This comment has been minimized.

Copy link
Author

dtolnay commented Aug 21, 2017

I filed #697 to follow up if necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.