Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@peterbudai
Created June 25, 2019 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterbudai/a0bc6617c138b84c7647008e3f311d1e to your computer and use it in GitHub Desktop.
Save peterbudai/a0bc6617c138b84c7647008e3f311d1e to your computer and use it in GitHub Desktop.
Stream combinator for different underlying stream types
/// Either is not implemented for Streams in futures 0.1.x, so we use our own.
enum EitherStream<A, B> {
A(A),
B(B),
}
impl<A, B> Stream for EitherStream<A, B>
where
A: Stream,
B: Stream<Item = A::Item, Error = A::Error>,
{
type Item = A::Item;
type Error = A::Error;
fn poll(&mut self) -> Poll<Option<A::Item>, A::Error> {
match *self {
EitherStream::A(ref mut a) => a.poll(),
EitherStream::B(ref mut b) => b.poll(),
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment