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

StreamExt::scan is barely useful due to lifetime issue #2171

Closed
jerry73204 opened this issue Jun 1, 2020 · 3 comments · Fixed by #2427
Closed

StreamExt::scan is barely useful due to lifetime issue #2171

jerry73204 opened this issue Jun 1, 2020 · 3 comments · Fixed by #2427
Labels
A-stream Area: futures::stream

Comments

@jerry73204
Copy link

Continuing #2046, the lifetime issue is still a headache, that the async block basically cannot access the state when it's executed. Currently, I stick to futures::stream::unfold workaround to bind streams with states.. IMO, the future block of scan could own the state and returns to stream just like what unfold did . Perhaps we can make this change, or are there any other considerations for this design?

@ivormetcalf
Copy link

ivormetcalf commented Aug 16, 2020

I just ran into this problem and wholeheartedly agree. Something like:

fn scan<S, B, Fut, F>(self, initial_state: S, f: F) -> Scan<Self, S, Fut, F>
where
    F: FnMut(S, Self::Item) -> Fut,
    Fut: Future<Output = Option<(B, S)>>, 

might perhaps be a better design.

@jerry73204
Copy link
Author

@ivormetcalf you can use code block quote for better readability.

@taiki-e taiki-e added A-stream Area: futures::stream and removed futures-util labels Dec 17, 2020
@taiki-e taiki-e added this to the futures-0.4 milestone Dec 17, 2020
@hjfreyer
Copy link

hjfreyer commented Jan 3, 2021

Does anyone know of a library that implements @ivormetcalf 's proposed signature?

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 a pull request may close this issue.

4 participants