[Solved] Error that Stream doesn't impl Future with futures-preview alpha

#1

I’m working on a program that uses the futures 0.3 alpha/stdlib integration and getting an error I can’t figure out. The error and the code are in the linked gist.

The ActionStream type that the function returns is defined as:

pub type ActionStream = Box<dyn Stream<Item = Result<Action, Error>> + Unpin>;

Where Action and Error are enums defined in the same crate.

The general flow of the function is that it checks for the presence of some data in a data store, which is a regular old Future, and then returns either a stream containing a single item (if the data was present) or an empty stream. So the value returned by the function needs to be a stream, but the result of a future is needed to determine what the returned stream should contain.

I’m confused by the error I’m getting, which implies that ActionStream does not implement Future, but streams do implement Future, so there is some subtlety here that I’m not able to parse out of the long, confusing trait bounds shown in the compiler output. Any help would be appreciated!

0 Likes

#2

I was able to make progress on this after some rubber duck debugging on reddit: https://www.reddit.com/r/rust/comments/asv6iu/help_needed_with_creating_a_stream_that_depends/

tl;dr My function can’t return a stream, it needs to return a future of a stream.

0 Likes