futures::StreamExt::into_future, what am I missing?

It happens you have to wait for a stream to end, while you don't care for the actual elements. You just need to continue polling it for side-effects.

I really felt into_future sounds great for that, but it seems it does more or less the same as next instead.

Looking through all of the methods on StreamExt, I can't find anything that does this elegantly. Even this won't work because of type inference problems: stream.skip_while( |_| true.into() ).

So am I stuck with: async move { while let Some(_) = stream.next().await {} };.

Is there a more elegant way to write this?
Why do we have the into_future one if we can use next?

Something along these lines might work (assuming you're on futures 0.3, might be slightly different on earlier versions):

use futures::future;
use futures::stream::StreamExt;

let fut = stream.for_each(|_| future::ready(()));
1 Like

yep, it works. I have to admit I still don't like it, but it's shorter than creating an async block. Thanks.

1 Like

There's an existing feature request for a dedicated method for this here, might be worth chiming in there if you think there's a big need for it!

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.