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

add stream::peekable #366

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft

Conversation

starsheriff
Copy link
Contributor

@starsheriff starsheriff commented Oct 17, 2019

Currently everything is breaking. I am still trying to figure out the type. I guess that peek should return a Future

pub fn peak(&mut self) -> &PeekFuture<Option<Self::Item>>

ref #129

}
None => {
let next = futures_core::ready!(self.as_mut().stream().poll_next(cx));
match next {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

match is redundant.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Poll::Ready(next)

Some(_) => {
let v = Poll::Ready(self.as_mut().peeked().take().unwrap());
*self.as_mut().peeked() = None;
v
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, the peeked just should hold the next. And every poll_next, it will be changed to new next. Why do *self.as_mut().peeked() = None;

S: Stream,
{
pin_utils::unsafe_pinned!(stream: S);
pin_utils::unsafe_unpinned!(peeked: Option<Option<S::Item>>);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice if this could be updated to use pin-project-lite the way we've done for other combinators (we merged this in the last week; in general it should be nicer!)

@yoshuawuyts
Copy link
Contributor

@starsheriff ping; just checking in if there's anything we can do to help unblock you. I'd very much would like to see this PR land!

@yoshuawuyts yoshuawuyts added the enhancement New feature or request label Oct 28, 2019
@starsheriff
Copy link
Contributor Author

@starsheriff ping; just checking in if there's anything we can do to help unblock you. I'd very much would like to see this PR land!

The comments I got helped a lot already. Haven't had the time the last days to work on it but will pick it up again now. I will ask if I need more help.

S: Sized,
{
stream: S,
peeked: Option<Poll<Option<S::Item>>>,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is what I landed on as the value for peeked

match &self.peeked {
Some(peeked) => &peeked,
None => {
// how to get the next `next` value? What about `Context`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is where I currently have troubles @yoshuawuyts , I have no idea how to get the next next value from here. Given that I store a Option<Poll<Option<S::Item>>> in the struct.

@yoshuawuyts yoshuawuyts mentioned this pull request Nov 15, 2019
87 tasks
@yjhmelody
Copy link
Contributor

@starsheriff The peek seem to be diffcult to impl. And if things are async, I think the peek is not very
useful.

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

Successfully merging this pull request may close these issues.

None yet

3 participants