Idiomatic way to use GATs to have a type that can be a Stream or a Future?

I wanted to know if there is an idiomatic way to use GATs to generate some kind of type that could be implemented by either a Stream<Item=T> or a Future<Output=T>;

The intention be to allow the user to return some kind of AsyncResponse<T> that somehow both a Stream and a Future can implement.

Bonus points if there is a way to also have the AsyncResponse also support being instantiated from a plain T as well.

Isn't that just Once?

If you want something like

impl<T, S: Stream<Item = T>> AsyncResponse<T> for S { /* ... */ }
impl<T, F: Future<Output = T>> AsyncResponse<T> for F { /* ... */ }

That can't work because I'm allowed to implement both Stream and Future for my own types, so the two implementations must conflict.

1 Like

The conflicting nature is the issue that I was hoping may have a workaround, but it makes sense that it unfortunately does not.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.