1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/// stream is Iterator
pub use Iterator as Stream;

pub trait TryStream: Stream {
    /// The type of successful values yielded by this future
    type Ok;

    /// The type of failures yielded by this future
    type Error;

    /// Poll this `TryStream` as if it were a `Stream`.
    fn try_next(&mut self) -> Option<Result<Self::Ok, Self::Error>>;
}


impl<S, T, E> TryStream for S
    where
        S: ?Sized + Stream<Item=Result<T, E>>,
{
    type Ok = T;
    type Error = E;

    fn try_next(&mut self) -> Option<Result<Self::Ok, Self::Error>> {
        self.next()
    }
}