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

Should provide function returning future for Peekable::peek #1871

Closed
Nemo157 opened this issue Sep 15, 2019 · 1 comment · Fixed by #2021
Closed

Should provide function returning future for Peekable::peek #1871

Nemo157 opened this issue Sep 15, 2019 · 1 comment · Fixed by #2021

Comments

@Nemo157
Copy link
Member

Nemo157 commented Sep 15, 2019

The current Peekable::peek signature doesn't seem right to me when related to other methods:

pub fn peek(
    self: Pin<&mut Peekable<St>>, 
    cx: &mut Context
) -> Poll<Option<&<St as Stream>::Item>>

I think this should be renamed to poll_peek, and another function added that returns a Future resolving to the peeked item:

pub fn peek(self: Pin<&mut Self>) -> impl Future<Output = Option<&<St as Stream>::Item>>;

Preferably this should also take something like &mut self where Self: Unpin to really avoid the issue from the below linked thread, unfortunately making a really useful signature like that would probably require defining an extra extension trait so that a Pin<impl DerefMut<Target = Peekable<_>>> would also be a Peekable.

(Related to this u.rl.o thread)

@cramertj cramertj added this to the 0.3 release milestone Oct 30, 2019
@cramertj cramertj removed this from the 0.3 release milestone Nov 5, 2019
@brennie
Copy link

brennie commented Nov 13, 2019

The docs on Peekable are also incorrect and imply that peek() exists.

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

Successfully merging a pull request may close this issue.

3 participants