-
Notifications
You must be signed in to change notification settings - Fork 653
replace unfold
with from_fn
#1609
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
Comments
aaaand unfortunately this doesn't work out today because the returned async body can't reference upvars from the closure passed in, so we still need |
FWIW, we can finally implement this on |
@danielhenrymantilla Unfortunately, I believe it's still not possible to spell this API without return type notation or type alias impl trait. Without these features, there's no way to spell this struct: pub struct FromFn<'a, Item, F: AsyncFnMut() -> Option<Item>> {
func: F,
ongoing_future: Option<F::CallRefFuture<'a>>, // `CallRefFuture` aka `F::async_call_mut(...)` isn't stable
} |
Do we necessarily need it to be named? The closure param inside it will remain hard-to-name, so I'd imagine we can bite the bullet and just involve an use ::futures::stream::{self, Stream};
fn from_fn<Item>(
f: impl AsyncFnMut() -> Option<Item>,
) -> impl Stream<Item = Item> {
stream::unfold(f, |mut f| async move {
Some((f().await?, f))
})
} |
a la https://doc.rust-lang.org/std/iter/fn.from_fn.html
The text was updated successfully, but these errors were encountered: