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

Change StreamExt::scan to pass state to closure by value #2427

Merged
merged 1 commit into from
May 12, 2021
Merged

Conversation

taiki-e
Copy link
Member

@taiki-e taiki-e commented May 8, 2021

Fixes #2171

      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,
-         Fut: Future<Output = Option<B>>,
+         F: FnMut(S, Self::Item) -> Fut,
+         Fut: Future<Output = Option<(S, B)>>,
          Self: Sized,

Related: #1609 (comment), #2254 (comment)

@taiki-e taiki-e added this to the futures-0.4, futures-core-1.0 milestone May 8, 2021
@taiki-e taiki-e added the A-stream Area: futures::stream label May 8, 2021
@taiki-e taiki-e force-pushed the stream-scan branch 2 times, most recently from e2bfdeb to d15a5fe Compare May 8, 2021 09:40
@taiki-e
Copy link
Member Author

taiki-e commented May 8, 2021

FYI @cramertj @olegnn

F: FnMut(&mut S, Self::Item) -> Fut,
Fut: Future<Output = Option<B>>,
F: FnMut(S, Self::Item) -> Fut,
Fut: Future<Output = Option<(S, B)>>,
Copy link
Member Author

Choose a reason for hiding this comment

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

    Fut: Future<Output = Option<(S, B)>>,

Hmm, it seems this (state, item) is the reverse order of the tuples returned by unfold's closure (item, state). However, given the order of arguments of scan/forld's closure (state, item), I feel this is reasonable.

@taiki-e taiki-e merged commit 83bc9a1 into master May 12, 2021
@taiki-e taiki-e deleted the stream-scan branch May 12, 2021 13:45
@benluelo
Copy link

benluelo commented Sep 7, 2023

Are there plans to cut a new release containing this change? Considering it was over 2 years go, I'm quite surprised it's still unreleased: https://docs.rs/futures/latest/futures/stream/trait.StreamExt.html#method.scan

@taiki-e
Copy link
Member Author

taiki-e commented Sep 7, 2023

This is a breaking change. Unfortunately, breaking releases of such widely used crates cannot be released often, as they have a significant impact on the ecosystem. This will be released once many (some?) other issues included in the milestone are resolved, so please consider helping to resolve the other issues included in the milestone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-stream Area: futures::stream
Projects
None yet
Development

Successfully merging this pull request may close these issues.

StreamExt::scan is barely useful due to lifetime issue
2 participants