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 StreamExt::scan #2044

Merged
merged 4 commits into from
Jan 21, 2020
Merged

Add StreamExt::scan #2044

merged 4 commits into from
Jan 21, 2020

Conversation

olegnn
Copy link
Contributor

@olegnn olegnn commented Jan 20, 2020

This PR adds combinator similar to https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.scan.
It may be useful for some cases when it's needed to cut stream or transform one stream into another using some state-based computations.

@olegnn olegnn changed the title Added StreamExt::scan Add StreamExt::scan Jan 20, 2020
/// ```
fn scan<S, B, Fut, F>(self, initial_state: S, f: F) -> Scan<Self, S, Fut, F>
where
F: FnMut(&mut S, Self::Item) -> Fut,
Copy link
Member

Choose a reason for hiding this comment

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

There isn't a way to fix this at the moment, sadly, but this is subtly the wrong method signature for this function, because it doesn't allow Fut to hold onto &mut S. There's no way to fix this right now due to limitations of HRTBs / GATs, so I don't mind accepting this PR now, but note that this makes this API dramatically less useful than it could be otherwise.

@cramertj cramertj merged commit 6b0e6dc into rust-lang:master Jan 21, 2020
@cramertj
Copy link
Member

Thanks for the PR! If you have time to send a PR to add documentation about the restriction I listed above, that'd be perfect, but no worries if not!

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 this pull request may close these issues.

3 participants